home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / u_man / cat1 / perlfunc.Z / perlfunc
Encoding:
Text File  |  1998-10-28  |  217.0 KB  |  6,403 lines

  1.  
  2.  
  3.  
  4.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       perlfunc - Perl builtin functions
  10.  
  11.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  12.       The functions    in this    section    can serve as terms in an
  13.       expression.  They fall into two major    categories: list
  14.       operators and    named unary operators.    These differ in    their
  15.       precedence relationship with a following comma.  (See    the
  16.       precedence table in the _p_e_r_l_o_p manpage.)  List operators
  17.       take more than one argument, while unary operators can never
  18.       take more than one argument.    Thus, a    comma terminates the
  19.       argument of a    unary operator,    but merely separates the
  20.       arguments of a list operator.     A unary operator generally
  21.       provides a scalar context to its argument, while a list
  22.       operator may provide either scalar and list contexts for its
  23.       arguments.  If it does both, the scalar arguments will be
  24.       first, and the list argument will follow.  (Note that    there
  25.       can ever be only one list argument.)    For instance, _s_p_l_i_c_e()
  26.       has three scalar arguments followed by a list.
  27.  
  28.       In the syntax    descriptions that follow, list operators that
  29.       expect a list    (and provide list context for the elements of
  30.       the list) are    shown with LIST    as an argument.     Such a    list
  31.       may consist of any combination of scalar arguments or    list
  32.       values; the list values will be included in the list as if
  33.       each individual element were interpolated at that point in
  34.       the list, forming a longer single-dimensional    list value.
  35.       Elements of the LIST should be separated by commas.
  36.  
  37.       Any function in the list below may be    used either with or
  38.       without parentheses around its arguments.  (The syntax
  39.       descriptions omit the    parentheses.)  If you use the
  40.       parentheses, the simple (but occasionally surprising)    rule
  41.       is this: It _L_O_O_K_S like a function, therefore it _I_S a
  42.       function, and    precedence doesn't matter.  Otherwise it's a
  43.       list operator    or unary operator, and precedence does matter.
  44.       And whitespace between the function and left parenthesis
  45.       doesn't count--so you    need to    be careful sometimes:
  46.  
  47.           print 1+2+4;      # Prints 7.
  48.           print(1+2) + 4;      # Prints 3.
  49.           print (1+2)+4;      # Also prints    3!
  50.           print +(1+2)+4;      # Prints 7.
  51.           print ((1+2)+4);      # Prints 7.
  52.  
  53.       If you run Perl with the ----wwww switch it    can warn you about
  54.       this.     For example, the third    line above produces:
  55.  
  56.           print (...) interpreted as function at - line 1.
  57.           Useless use of integer addition in void context at - line    1.
  58.  
  59.       For functions    that can be used in either a scalar or list
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  71.  
  72.  
  73.  
  74.       context, nonabortive failure is generally indicated in a
  75.       scalar context by returning the undefined value, and in a
  76.       list context by returning the    null list.
  77.  
  78.       Remember the following important rule: There is nnnnoooo rrrruuuulllleeee that
  79.       relates the behavior of an expression    in list    context    to its
  80.       behavior in scalar context, or vice versa.  It might do two
  81.       totally different things.  Each operator and function
  82.       decides which    sort of    value it would be most appropriate to
  83.       return in a scalar context.  Some operators return the
  84.       length of the    list that would    have been returned in list
  85.       context.  Some operators return the first value in the list.
  86.       Some operators return    the last value in the list.  Some
  87.       operators return a count of successful operations.  In
  88.       general, they    do what    you want, unless you want consistency.
  89.  
  90.       An named array in scalar context is quite different from
  91.       what would at    first glance appear to be a list in scalar
  92.       context.  You    can't get a list like (1,2,3) into being in
  93.       scalar context, because the compiler knows the context at
  94.       compile time.     It would generate the scalar comma operator
  95.       there, not the list construction version of the comma.  That
  96.       means    it was never a list to start with.
  97.  
  98.       In general, functions    in Perl    that serve as wrappers for
  99.       system calls of the same name    (like _c_h_o_w_n(2),    _f_o_r_k(2),
  100.       _c_l_o_s_e_d_i_r(2), etc.) all return    true when they succeed and
  101.       undef    otherwise, as is usually mentioned in the descriptions
  102.       below.  This is different from the C interfaces, which
  103.       return -1 on failure.     Exceptions to this rule are wait(),
  104.       waitpid(), and syscall().  System calls also set the special
  105.       $!  variable on failure.  Other functions do not, except
  106.       accidentally.
  107.  
  108.       PPPPeeeerrrrllll FFFFuuuunnnnccccttttiiiioooonnnnssss bbbbyyyy CCCCaaaatttteeeeggggoooorrrryyyy
  109.  
  110.       Here are Perl's functions (including things that look    like
  111.       functions, like some keywords    and named operators) arranged
  112.       by category.    Some functions appear in more than one place.
  113.  
  114.       Functions for    SCALARs    or strings
  115.            chomp, chop, chr, crypt,    hex, index, lc,    lcfirst,
  116.            length, oct, ord, pack, q/STRING/, qq/STRING/, reverse,
  117.            rindex, sprintf,    substr,    tr///, uc, ucfirst, y///
  118.  
  119.       Regular expressions and pattern matching
  120.            m//, pos, quotemeta, s///, split, study,    qr//
  121.  
  122.       Numeric functions
  123.            abs, atan2, cos,    exp, hex, int, log, oct, rand, sin,
  124.            sqrt, srand
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  137.  
  138.  
  139.  
  140.       Functions for    real @ARRAYs
  141.            pop, push, shift, splice, unshift
  142.  
  143.       Functions for    list data
  144.            grep, join, map,    qw/STRING/, reverse, sort, unpack
  145.  
  146.       Functions for    real %HASHes
  147.            delete, each, exists, keys, values
  148.  
  149.       Input    and output functions
  150.            binmode,    close, closedir, dbmclose, dbmopen, die, eof,
  151.            fileno, flock, format, getc, print, printf, read,
  152.            readdir,    rewinddir, seek, seekdir, select, syscall,
  153.            sysread,    sysseek, syswrite, tell, telldir, truncate,
  154.            warn, write
  155.  
  156.       Functions for    fixed length data or records
  157.            pack, read, syscall, sysread, syswrite, unpack, vec
  158.  
  159.       Functions for    filehandles, files, or directories
  160.            -_X, chdir, chmod, chown,    chroot,    fcntl, glob, ioctl,
  161.            link, lstat, mkdir, open, opendir, readlink, rename,
  162.            rmdir, stat, symlink, umask, unlink, utime
  163.  
  164.       Keywords related to the control flow of your perl program
  165.            caller, continue, die, do, dump,    eval, exit, goto,
  166.            last, next, redo, return, sub, wantarray
  167.  
  168.       Keywords related to scoping
  169.            caller, import, local, my, package, use
  170.  
  171.       Miscellaneous    functions
  172.            defined,    dump, eval, formline, local, my, reset,
  173.            scalar, undef, wantarray
  174.  
  175.       Functions for    processes and process groups
  176.            alarm, exec, fork, getpgrp, getppid, getpriority, kill,
  177.            pipe, qx/STRING/, setpgrp, setpriority, sleep, system,
  178.            times, wait, waitpid
  179.  
  180.       Keywords related to perl modules
  181.            do, import, no, package,    require, use
  182.  
  183.       Keywords related to classes and object-orientedness
  184.            bless, dbmclose,    dbmopen, package, ref, tie, tied,
  185.            untie, use
  186.  
  187.       Low-level socket functions
  188.            accept, bind, connect, getpeername, getsockname,
  189.            getsockopt, listen, recv, send, setsockopt, shutdown,
  190.            socket, socketpair
  191.  
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  203.  
  204.  
  205.  
  206.       System V interprocess    communication functions
  207.            msgctl, msgget, msgrcv, msgsnd, semctl, semget, semop,
  208.            shmctl, shmget, shmread,    shmwrite
  209.  
  210.       Fetching user    and group info
  211.            endgrent, endhostent, endnetent,    endpwent, getgrent,
  212.            getgrgid, getgrnam, getlogin, getpwent, getpwnam,
  213.            getpwuid, setgrent, setpwent
  214.  
  215.       Fetching network info
  216.            endprotoent, endservent,    gethostbyaddr, gethostbyname,
  217.            gethostent, getnetbyaddr, getnetbyname, getnetent,
  218.            getprotobyname, getprotobynumber, getprotoent,
  219.            getservbyname, getservbyport, getservent, sethostent,
  220.            setnetent, setprotoent, setservent
  221.  
  222.       Time-related functions
  223.            gmtime, localtime, time,    times
  224.  
  225.       Functions new    in perl5
  226.            abs, bless, chomp, chr, exists, formline, glob, import,
  227.            lc, lcfirst, map, my, no, prototype, qx,    qw, readline,
  228.            readpipe, ref, sub*, sysopen, tie, tied,    uc, ucfirst,
  229.            untie, use
  230.  
  231.            * - sub was a keyword in    perl4, but in perl5 it is an
  232.            operator, which can be used in expressions.
  233.  
  234.       Functions obsoleted in perl5
  235.            dbmclose, dbmopen
  236.  
  237.       AAAAllllpppphhhhaaaabbbbeeeettttiiiiccccaaaallll LLLLiiiissssttttiiiinnnngggg ooooffff PPPPeeeerrrrllll FFFFuuuunnnnccccttttiiiioooonnnnssss
  238.  
  239.       -_X FILEHANDLE
  240.  
  241.       -_X EXPR
  242.  
  243.       -_X      A file test, where X is one of the letters listed
  244.           below.  This unary operator takes one    argument,
  245.           either a filename or a filehandle, and tests the
  246.           associated file to see if something is true about
  247.           it.  If the argument is omitted, tests $_, except
  248.           for -t, which    tests STDIN.  Unless otherwise
  249.           documented, it returns 1 for TRUE and    '' for FALSE,
  250.           or the undefined value if the    file doesn't exist.
  251.           Despite the funny names, precedence is the same as
  252.           any other named unary    operator, and the argument may
  253.           be parenthesized like    any other unary    operator.  The
  254.           operator may be any of:
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                        (printed 10/23/98)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  269.  
  270.  
  271.  
  272.               -r  File is readable by effective    uid/gid.
  273.               -w  File is writable by effective    uid/gid.
  274.               -x  File is executable by    effective uid/gid.
  275.               -o  File is owned    by effective uid.
  276.  
  277.               -R  File is readable by real uid/gid.
  278.               -W  File is writable by real uid/gid.
  279.               -X  File is executable by    real uid/gid.
  280.               -O  File is owned    by real    uid.
  281.  
  282.               -e  File exists.
  283.               -z  File has zero    size.
  284.               -s  File has nonzero size    (returns size).
  285.  
  286.               -f  File is a plain file.
  287.               -d  File is a directory.
  288.               -l  File is a symbolic link.
  289.               -p  File is a named pipe (FIFO), or Filehandle is    a pipe.
  290.               -S  File is a socket.
  291.               -b  File is a block special file.
  292.               -c  File is a character special file.
  293.               -t  Filehandle is    opened to a tty.
  294.  
  295.               -u  File has setuid bit set.
  296.               -g  File has setgid bit set.
  297.               -k  File has sticky bit set.
  298.  
  299.               -T  File is a text file.
  300.               -B  File is a binary file    (opposite of -T).
  301.  
  302.               -M  Age of file in days when script started.
  303.               -A  Same for access time.
  304.               -C  Same for inode change    time.
  305.  
  306.           The interpretation of    the file permission operators
  307.           -r, -R, -w, -W, -x, and -X is    based solely on    the
  308.           mode of the file and the uids    and gids of the    user.
  309.           There    may be other reasons you can't actually    read,
  310.           write, or execute the    file, such as AFS access
  311.           control lists.  Also note that, for the superuser,
  312.           -r, -R, -w, and -W always return 1, and -x and -X
  313.           return 1 if any execute bit is set in    the mode.
  314.           Scripts run by the superuser may thus    need to    do a
  315.           stat() to determine the actual mode of the file, or
  316.           temporarily set the uid to something else.
  317.  
  318.           Example:
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.      Page 5                        (printed 10/23/98)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  335.  
  336.  
  337.  
  338.               while (<>) {
  339.               chop;
  340.               next unless -f $_;      # ignore specials
  341.               #...
  342.               }
  343.  
  344.           Note that -s/a/b/ does not do    a negated
  345.           substitution.     Saying    -exp($foo) still works as
  346.           expected, however--only single letters following a
  347.           minus    are interpreted    as file    tests.
  348.  
  349.           The -T and -B    switches work as follows.  The first
  350.           block    or so of the file is examined for odd
  351.           characters such as strange control codes or
  352.           characters with the high bit set.  If    too many
  353.           strange characters (>30%) are    found, it's a -B file,
  354.           otherwise it's a -T file.  Also, any file containing
  355.           null in the first block is considered    a binary file.
  356.           If -T    or -B is used on a filehandle, the current
  357.           stdio    buffer is examined rather than the first
  358.           block.  Both -T and -B return    TRUE on    a null file,
  359.           or a file at EOF when    testing    a filehandle.  Because
  360.           you have to read a file to do    the -T test, on    most
  361.           occasions you    want to    use a -f against the file
  362.           first, as in next unless -f $file && -T $file.
  363.  
  364.           If any of the    file tests (or either the stat() or
  365.           lstat() operators) are given the special filehandle
  366.           consisting of    a solitary underline, then the stat
  367.           structure of the previous file test (or stat
  368.           operator) is used, saving a system call.  (This
  369.           doesn't work with -t,    and you    need to    remember that
  370.           _l_s_t_a_t() and -l will leave values in the stat
  371.           structure for    the symbolic link, not the real    file.)
  372.           Example:
  373.  
  374.               print "Can do.\n"    if -r $a || -w _ || -x _;
  375.  
  376.               stat($filename);
  377.               print "Readable\n" if -r _;
  378.               print "Writable\n" if -w _;
  379.               print "Executable\n" if -x _;
  380.               print "Setuid\n" if -u _;
  381.               print "Setgid\n" if -g _;
  382.               print "Sticky\n" if -k _;
  383.               print "Text\n" if    -T _;
  384.               print "Binary\n" if -B _;
  385.  
  386.  
  387.       abs VALUE
  388.  
  389.  
  390.  
  391.  
  392.  
  393.      Page 6                        (printed 10/23/98)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  401.  
  402.  
  403.  
  404.       abs      Returns the absolute value of    its argument.  If
  405.           VALUE    is omitted, uses $_.
  406.  
  407.       accept NEWSOCKET,GENERICSOCKET
  408.           Accepts an incoming socket connect, just as the
  409.           _a_c_c_e_p_t(2) system call    does.  Returns the packed
  410.           address if it    succeeded, FALSE otherwise.  See
  411.           example in the section on _S_o_c_k_e_t_s: _C_l_i_e_n_t/_S_e_r_v_e_r
  412.           _C_o_m_m_u_n_i_c_a_t_i_o_n    in the _p_e_r_l_i_p_c manpage.
  413.  
  414.       alarm    SECONDS
  415.  
  416.       alarm      Arranges to have a SIGALRM delivered to this process
  417.           after    the specified number of    seconds    have elapsed.
  418.           If SECONDS is    not specified, the value stored    in $_
  419.           is used. (On some machines, unfortunately, the
  420.           elapsed time may be up to one    second less than you
  421.           specified because of how seconds are counted.)  Only
  422.           one timer may    be counting at once.  Each call
  423.           disables the previous    timer, and an argument of 0
  424.           may be supplied to cancel the    previous timer without
  425.           starting a new one.  The returned value is the
  426.           amount of time remaining on the previous timer.
  427.  
  428.           For delays of    finer granularity than one second, you
  429.           may use Perl's syscall() interface to    access
  430.           _s_e_t_i_t_i_m_e_r(2) if your system supports it, or else see
  431.           the select() entry elsewhere in this document.  It
  432.           is usually a mistake to intermix alarm() and sleep()
  433.           calls.
  434.  
  435.           If you want to use alarm() to    time out a system call
  436.           you need to use an eval()/die() pair.     You can't
  437.           rely on the alarm causing the    system call to fail
  438.           with $! set to EINTR because Perl sets up signal
  439.           handlers to restart system calls on some systems.
  440.           Using    eval()/die() always works, modulo the caveats
  441.           given    in the section on _S_i_g_n_a_l_s in the _p_e_r_l_i_p_c
  442.           manpage.
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.      Page 7                        (printed 10/23/98)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  467.  
  468.  
  469.  
  470.               eval {
  471.               local    $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
  472.               alarm    $timeout;
  473.               $nread = sysread SOCKET, $buffer, $size;
  474.               alarm    0;
  475.               };
  476.               if ($@) {
  477.               die unless $@    eq "alarm\n";    # propagate unexpected errors
  478.               # timed out
  479.               }
  480.               else {
  481.               # didn't
  482.               }
  483.  
  484.  
  485.       atan2    Y,X
  486.           Returns the arctangent of Y/X    in the range -pi to
  487.           pi.
  488.  
  489.           For the tangent operation, you may use the
  490.           POSIX::tan() function, or use    the familiar relation:
  491.  
  492.               sub tan {    sin($_[0]) / cos($_[0])     }
  493.  
  494.  
  495.       bind SOCKET,NAME
  496.           Binds    a network address to a socket, just as the
  497.           bind system call does.  Returns TRUE if it
  498.           succeeded, FALSE otherwise.  NAME should be a    packed
  499.           address of the appropriate type for the socket.  See
  500.           the examples in the section on _S_o_c_k_e_t_s:
  501.           _C_l_i_e_n_t/_S_e_r_v_e_r    _C_o_m_m_u_n_i_c_a_t_i_o_n in the _p_e_r_l_i_p_c manpage.
  502.  
  503.       binmode FILEHANDLE
  504.           Arranges for the file    to be read or written in
  505.           "binary" mode    in operating systems that distinguish
  506.           between binary and text files.  Files    that are not
  507.           in binary mode have CR LF sequences translated to LF
  508.           on input and LF translated to    CR LF on output.
  509.           Binmode has no effect    under Unix; in MS-DOS and
  510.           similarly archaic systems, it    may be imperative--
  511.           otherwise your MS-DOS-damaged    C library may mangle
  512.           your file.  The key distinction between systems that
  513.           need binmode() and those that    don't is their text
  514.           file formats.     Systems like Unix, MacOS, and Plan9
  515.           that delimit lines with a single character, and that
  516.           encode that character    in C as    "\n", do not need
  517.           binmode().  The rest need it.     If FILEHANDLE is an
  518.           expression, the value    is taken as the    name of    the
  519.           filehandle.
  520.  
  521.  
  522.  
  523.  
  524.  
  525.      Page 8                        (printed 10/23/98)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  533.  
  534.  
  535.  
  536.       bless    REF,CLASSNAME
  537.  
  538.       bless    REF
  539.           This function    tells the thingy referenced by REF
  540.           that it is now an object in the CLASSNAME package--
  541.           or the current package if no CLASSNAME is specified,
  542.           which    is often the case.  It returns the reference
  543.           for convenience, because a bless() is    often the last
  544.           thing    in a constructor.  Always use the two-argument
  545.           version if the function doing    the blessing might be
  546.           inherited by a derived class.     See the _p_e_r_l_t_o_o_t
  547.           manpage and the _p_e_r_l_o_b_j manpage for more about the
  548.           blessing (and    blessings) of objects.
  549.  
  550.       caller EXPR
  551.  
  552.       caller  Returns the context of the current subroutine    call.
  553.           In scalar context, returns the caller's package name
  554.           if there is a    caller,    that is, if we're in a
  555.           subroutine or    eval() or require(), and the undefined
  556.           value    otherwise.  In list context, returns
  557.  
  558.               ($package, $filename, $line) = caller;
  559.  
  560.           With EXPR, it    returns    some extra information that
  561.           the debugger uses to print a stack trace.  The value
  562.           of EXPR indicates how    many call frames to go back
  563.           before the current one.
  564.  
  565.               ($package, $filename, $line, $subroutine,
  566.                $hasargs, $wantarray, $evaltext,    $is_require) = caller($i);
  567.  
  568.           Here $subroutine may be "(eval)" if the frame    is not
  569.           a subroutine call, but an eval().  In    such a case
  570.           additional elements $evaltext    and $is_require    are
  571.           set: $is_require is true if the frame    is created by
  572.           a require or use statement, $evaltext    contains the
  573.           text of the eval EXPR    statement.  In particular, for
  574.           a eval BLOCK statement, $filename is "(eval)", but
  575.           $evaltext is undefined.  (Note also that each    use
  576.           statement creates a require frame inside an eval
  577.           EXPR)    frame.
  578.  
  579.           Furthermore, when called from    within the DB package,
  580.           caller returns more detailed information: it sets
  581.           the list variable @DB::args to be the    arguments with
  582.           which    the subroutine was invoked.
  583.  
  584.           Be aware that    the optimizer might have optimized
  585.           call frames away before caller() had a chance    to get
  586.           the information. That    means that caller(N) might not
  587.           return information about the call frame you expect
  588.  
  589.  
  590.  
  591.      Page 9                        (printed 10/23/98)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  599.  
  600.  
  601.  
  602.           it do, for N > 1. In particular, @DB::args might
  603.           have information from    the previous time caller() was
  604.           called.
  605.  
  606.       chdir    EXPR
  607.           Changes the working directory    to EXPR, if possible.
  608.           If EXPR is omitted, changes to home directory.
  609.           Returns TRUE upon success, FALSE otherwise.  See
  610.           example under    die().
  611.  
  612.       chmod    LIST
  613.           Changes the permissions of a list of files.  The
  614.           first    element    of the list must be the    numerical
  615.           mode,    which should probably be an octal number, and
  616.           which    definitely should _n_o_t a    string of octal
  617.           digits:  0644    is okay, '0644'    is not.     Returns the
  618.           number of files successfully changed.     See also the
  619.           oct entry elsewhere in this documentif all you have
  620.           is a string.
  621.  
  622.               $cnt = chmod 0755, 'foo',    'bar';
  623.               chmod 0755, @executables;
  624.               $mode = '0644'; chmod $mode, 'foo';      # !!! sets mode to
  625.                                    # --w----r-T
  626.               $mode = '0644'; chmod oct($mode),    'foo'; # this is better
  627.               $mode = 0644;   chmod $mode, 'foo';      # this is best
  628.  
  629.  
  630.       chomp    VARIABLE
  631.  
  632.       chomp    LIST
  633.  
  634.       chomp      This is a slightly safer version of the chop entry
  635.           elsewhere in this document.  It removes any line
  636.           ending that corresponds to the current value of $/
  637.           (also    known as $INPUT_RECORD_SEPARATOR in the
  638.           English module).  It returns the total number    of
  639.           characters removed from all its arguments.  It's
  640.           often    used to    remove the newline from    the end    of an
  641.           input    record when you're worried that    the final
  642.           record may be    missing    its newline.  When in
  643.           paragraph mode ($/ = ""), it removes all trailing
  644.           newlines from    the string.  If    VARIABLE is omitted,
  645.           it chomps $_.     Example:
  646.  
  647.               while (<>) {
  648.               chomp;  # avoid \n on    last field
  649.               @array = split(/:/);
  650.               # ...
  651.               }
  652.  
  653.           You can actually chomp anything that's an lvalue,
  654.  
  655.  
  656.  
  657.      Page 10                        (printed 10/23/98)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  665.  
  666.  
  667.  
  668.           including an assignment:
  669.  
  670.               chomp($cwd = `pwd`);
  671.               chomp($answer = <STDIN>);
  672.  
  673.           If you chomp a list, each element is chomped,    and
  674.           the total number of characters removed is returned.
  675.  
  676.       chop VARIABLE
  677.  
  678.       chop LIST
  679.  
  680.       chop      Chops    off the    last character of a string and returns
  681.           the character    chopped.  It's used primarily to
  682.           remove the newline from the end of an    input record,
  683.           but is much more efficient than s/\n// because it
  684.           neither scans    nor copies the string.    If VARIABLE is
  685.           omitted, chops $_.  Example:
  686.  
  687.               while (<>) {
  688.               chop;      # avoid \n on    last field
  689.               @array = split(/:/);
  690.               #...
  691.               }
  692.  
  693.           You can actually chop    anything that's    an lvalue,
  694.           including an assignment:
  695.  
  696.               chop($cwd    = `pwd`);
  697.               chop($answer = <STDIN>);
  698.  
  699.           If you chop a    list, each element is chopped.    Only
  700.           the value of the last    chop() is returned.
  701.  
  702.           Note that chop() returns the last character.    To
  703.           return all but the last character, use
  704.           substr($string, 0, -1).
  705.  
  706.       chown    LIST
  707.           Changes the owner (and group)    of a list of files.
  708.           The first two    elements of the    list must be the
  709.           _N_U_M_E_R_I_C_A_L uid    and gid, in that order.     Returns the
  710.           number of files successfully changed.
  711.  
  712.               $cnt = chown $uid, $gid, 'foo', 'bar';
  713.               chown $uid, $gid,    @filenames;
  714.  
  715.           Here's an example that looks up nonnumeric uids in
  716.           the passwd file:
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.      Page 11                        (printed 10/23/98)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  731.  
  732.  
  733.  
  734.               print "User: ";
  735.               chop($user = <STDIN>);
  736.               print "Files: ";
  737.               chop($pattern = <STDIN>);
  738.  
  739.               ($login,$pass,$uid,$gid) = getpwnam($user)
  740.               or die "$user    not in passwd file";
  741.  
  742.               @ary = glob($pattern);      # expand filenames
  743.               chown $uid, $gid,    @ary;
  744.  
  745.           On most systems, you are not allowed to change the
  746.           ownership of the file    unless you're the superuser,
  747.           although you should be able to change    the group to
  748.           any of your secondary    groups.     On insecure systems,
  749.           these    restrictions may be relaxed, but this is not a
  750.           portable assumption.
  751.  
  752.       chr NUMBER
  753.  
  754.       chr      Returns the character    represented by that NUMBER in
  755.           the character    set.  For example, chr(65) is "A" in
  756.           ASCII.  For the reverse, use the ord entry elsewhere
  757.           in this document.
  758.  
  759.           If NUMBER is omitted,    uses $_.
  760.  
  761.       chroot FILENAME
  762.  
  763.       chroot  This function    works like the system call by the same
  764.           name:    it makes the named directory the new root
  765.           directory for    all further pathnames that begin with
  766.           a "/"    by your    process    and all    its children.  (It
  767.           doesn't change your current working directory, which
  768.           is unaffected.)  For security    reasons, this call is
  769.           restricted to    the superuser.    If FILENAME is
  770.           omitted, does    a chroot() to $_.
  771.  
  772.       close    FILEHANDLE
  773.  
  774.       close      Closes the file or pipe associated with the file
  775.           handle, returning TRUE only if stdio successfully
  776.           flushes buffers and closes the system    file
  777.           descriptor. Closes the currently selected filehandle
  778.           if the argument is omitted.
  779.  
  780.           You don't have to close FILEHANDLE if    you are
  781.           immediately going to do another open() on it,
  782.           because open() will close it for you.     (See open().)
  783.           However, an explicit close() on an input file    resets
  784.           the line counter ($.), while the implicit close done
  785.           by open() does not.
  786.  
  787.  
  788.  
  789.      Page 12                        (printed 10/23/98)
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  797.  
  798.  
  799.  
  800.           If the file handle came from a piped open close()
  801.           will additionally return FALSE if one    of the other
  802.           system calls involved    fails or if the    program    exits
  803.           with non-zero    status.     (If the only problem was that
  804.           the program exited non-zero $! will be set to    0.)
  805.           Also,    closing    a pipe waits for the process executing
  806.           on the pipe to complete, in case you want to look at
  807.           the output of    the pipe afterwards.  Closing a    pipe
  808.           explicitly also puts the exit    status value of    the
  809.           command into $?.
  810.  
  811.           Example:
  812.  
  813.               open(OUTPUT, '|sort >foo')  # pipe to sort
  814.               or die "Can't    start sort: $!";
  815.               #...              # print stuff    to output
  816.               close OUTPUT          # wait for sort to finish
  817.               or warn $! ? "Error closing sort pipe: $!"
  818.                      : "Exit status $? from sort";
  819.               open(INPUT, 'foo')      # get    sort's results
  820.               or die "Can't    open 'foo' for input: $!";
  821.  
  822.           FILEHANDLE may be an expression whose    value can be
  823.           used as an indirect filehandle, usually the real
  824.           filehandle name.
  825.  
  826.       closedir DIRHANDLE
  827.           Closes a directory opened by opendir() and returns
  828.           the success of that system call.
  829.  
  830.           DIRHANDLE may    be an expression whose value can be
  831.           used as an indirect dirhandle, usually the real
  832.           dirhandle name.
  833.  
  834.       connect SOCKET,NAME
  835.           Attempts to connect to a remote socket, just as the
  836.           connect system call does.  Returns TRUE if it
  837.           succeeded, FALSE otherwise.  NAME should be a    packed
  838.           address of the appropriate type for the socket.  See
  839.           the examples in the section on _S_o_c_k_e_t_s:
  840.           _C_l_i_e_n_t/_S_e_r_v_e_r    _C_o_m_m_u_n_i_c_a_t_i_o_n in the _p_e_r_l_i_p_c manpage.
  841.  
  842.       continue BLOCK
  843.           Actually a flow control statement rather than    a
  844.           function.  If    there is a continue BLOCK attached to
  845.           a BLOCK (typically in    a while    or foreach), it    is
  846.           always executed just before the conditional is about
  847.           to be    evaluated again, just like the third part of a
  848.           for loop in C.  Thus it can be used to increment a
  849.           loop variable, even when the loop has    been continued
  850.           via the next statement (which    is similar to the C
  851.           continue statement).
  852.  
  853.  
  854.  
  855.      Page 13                        (printed 10/23/98)
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  863.  
  864.  
  865.  
  866.           last,    next, or redo may appear within    a continue
  867.           block. last and redo will behave as if they had been
  868.           executed within the main block. So will next,    but
  869.           since    it will    execute    a continue block, it may be
  870.           more entertaining.
  871.  
  872.               while (EXPR) {
  873.               ### redo always comes    here
  874.               do_something;
  875.               }    continue {
  876.               ### next always comes    here
  877.               do_something_else;
  878.               # then back the top to re-check EXPR
  879.               }
  880.               ### last always comes here
  881.  
  882.           Omitting the continue    section    is semantically
  883.           equivalent to    using an empty one, logically enough.
  884.           In that case,    next goes directly back    to check the
  885.           condition at the top of the loop.
  886.  
  887.       cos EXPR
  888.           Returns the cosine of    EXPR (expressed    in radians).
  889.           If EXPR is omitted, takes cosine of $_.
  890.  
  891.           For the inverse cosine operation, you    may use    the
  892.           POSIX::acos()    function, or use this relation:
  893.  
  894.               sub acos { atan2(    sqrt(1 - $_[0] * $_[0]), $_[0] ) }
  895.  
  896.  
  897.       crypt    PLAINTEXT,SALT
  898.           Encrypts a string exactly like the _c_r_y_p_t(3) function
  899.           in the C library (assuming that you actually have a
  900.           version there    that has not been extirpated as    a
  901.           potential munition).    This can prove useful for
  902.           checking the password    file for lousy passwords,
  903.           amongst other    things.     Only the guys wearing white
  904.           hats should do this.
  905.  
  906.           Note that crypt() is intended    to be a    one-way
  907.           function, much like breaking eggs to make an
  908.           omelette.  There is no (known) corresponding decrypt
  909.           function.  As    a result, this function    isn't all that
  910.           useful for cryptography.  (For that, see your    nearby
  911.           CPAN mirror.)
  912.  
  913.           Here's an example that makes sure that whoever runs
  914.           this program knows their own password:
  915.  
  916.               $pwd = (getpwuid($<))[1];
  917.               $salt = substr($pwd, 0, 2);
  918.  
  919.  
  920.  
  921.      Page 14                        (printed 10/23/98)
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  929.  
  930.  
  931.  
  932.               system "stty -echo";
  933.               print "Password: ";
  934.               chop($word = <STDIN>);
  935.               print "\n";
  936.               system "stty echo";
  937.  
  938.               if (crypt($word, $salt) ne $pwd) {
  939.               die "Sorry...\n";
  940.               }    else {
  941.               print    "ok\n";
  942.               }
  943.  
  944.           Of course, typing in your own    password to whoever
  945.           asks you for it is unwise.
  946.  
  947.       dbmclose HASH
  948.           [This    function has been superseded by    the untie()
  949.           function.]
  950.  
  951.           Breaks the binding between a DBM file    and a hash.
  952.  
  953.       dbmopen HASH,DBNAME,MODE
  954.           [This    function has been superseded by    the tie()
  955.           function.]
  956.  
  957.           This binds a _d_b_m(3), _n_d_b_m(3),    _s_d_b_m(3), _g_d_b_m(3), or
  958.           Berkeley DB file to a    hash.  HASH is the name    of the
  959.           hash.     (Unlike normal    open(),    the first argument is
  960.           _N_O_T a    filehandle, even though    it looks like one).
  961.           DBNAME is the    name of    the database (without the ._d_i_r
  962.           or ._p_a_g extension if any).  If the database does not
  963.           exist, it is created with protection specified by
  964.           MODE (as modified by the umask()).  If your system
  965.           supports only    the older DBM functions, you may
  966.           perform only one dbmopen() in    your program.  In
  967.           older    versions of Perl, if your system had neither
  968.           DBM nor ndbm,    calling    dbmopen() produced a fatal
  969.           error; it now    falls back to _s_d_b_m(3).
  970.  
  971.           If you don't have write access to the    DBM file, you
  972.           can only read    hash variables,    not set    them.  If you
  973.           want to test whether you can write, either use file
  974.           tests    or try setting a dummy hash entry inside an
  975.           eval(), which    will trap the error.
  976.  
  977.           Note that functions such as keys() and values() may
  978.           return huge lists when used on large DBM files.  You
  979.           may prefer to    use the    each() function    to iterate
  980.           over large DBM files.     Example:
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.      Page 15                        (printed 10/23/98)
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  995.  
  996.  
  997.  
  998.               #    print out history file offsets
  999.               dbmopen(%HIST,'/usr/lib/news/history',0666);
  1000.               while (($key,$val) = each    %HIST) {
  1001.               print    $key, '    = ', unpack('L',$val), "\n";
  1002.               }
  1003.               dbmclose(%HIST);
  1004.  
  1005.           See also the _A_n_y_D_B_M__F_i_l_e manpage for a more general
  1006.           description of the pros and cons of the various dbm
  1007.           approaches, as well as the _D_B__F_i_l_e manpage for a
  1008.           particularly rich implementation.
  1009.  
  1010.       defined EXPR
  1011.  
  1012.       defined Returns a Boolean value telling whether EXPR has a
  1013.           value    other than the undefined value undef.  If EXPR
  1014.           is not present, $_ will be checked.
  1015.  
  1016.           Many operations return undef to indicate failure,
  1017.           end of file, system error, uninitialized variable,
  1018.           and other exceptional    conditions.  This function
  1019.           allows you to    distinguish undef from other values.
  1020.           (A simple Boolean test will not distinguish among
  1021.           undef, zero, the empty string, and "0", which    are
  1022.           all equally false.)  Note that since undef is    a
  1023.           valid    scalar,    its presence doesn't _n_e_c_e_s_s_a_r_i_l_y
  1024.           indicate an exceptional condition: pop() returns
  1025.           undef    when its argument is an    empty array, _o_r    when
  1026.           the element to return    happens    to be undef.
  1027.  
  1028.           You may also use defined() to    check whether a
  1029.           subroutine exists, by    saying defined &func without
  1030.           parentheses.    On the other hand, use of defined()
  1031.           upon aggregates (hashes and arrays) is not
  1032.           guaranteed to    produce    intuitive results, and should
  1033.           probably be avoided.
  1034.  
  1035.           When used on a hash element, it tells    you whether
  1036.           the value is defined,    not whether the    key exists in
  1037.           the hash.  Use the exists entry elsewhere in this
  1038.           documentfor the latter purpose.
  1039.  
  1040.           Examples:
  1041.  
  1042.               print if defined $switch{'D'};
  1043.               print "$val\n" while defined($val    = pop(@ary));
  1044.               die "Can't readlink $sym:    $!"
  1045.               unless defined($value    = readlink $sym);
  1046.               sub foo {    defined    &$bar ?    &$bar(@_) : die    "No bar"; }
  1047.               $debugging = 0 unless defined $debugging;
  1048.  
  1049.           Note:     Many folks tend to overuse defined(), and
  1050.  
  1051.  
  1052.  
  1053.      Page 16                        (printed 10/23/98)
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1061.  
  1062.  
  1063.  
  1064.           then are surprised to    discover that the number 0 and
  1065.           "" (the zero-length string) are, in fact, defined
  1066.           values.  For example,    if you say
  1067.  
  1068.               "ab" =~ /a(.*)b/;
  1069.  
  1070.           The pattern match succeeds, and $1 is    defined,
  1071.           despite the fact that    it matched "nothing".  But it
  1072.           didn't really    match nothing--rather, it matched
  1073.           something that happened to be    0 characters long.
  1074.           This is all very above-board and honest.  When a
  1075.           function returns an undefined    value, it's an
  1076.           admission that it couldn't give you an honest
  1077.           answer.  So you should use defined() only when
  1078.           you're questioning the integrity of what you're
  1079.           trying to do.     At other times, a simple comparison
  1080.           to 0 or "" is    what you want.
  1081.  
  1082.           Currently, using defined() on    an entire array    or
  1083.           hash reports whether memory for that aggregate has
  1084.           ever been allocated.    So an array you    set to the
  1085.           empty    list appears undefined initially, and one that
  1086.           once was full    and that you then set to the empty
  1087.           list still appears defined.  You should instead use
  1088.           a simple test    for size:
  1089.  
  1090.               if (@an_array) { print "has array    elements\n" }
  1091.               if (%a_hash)   { print "has hash members\n"   }
  1092.  
  1093.           Using    undef()    on these, however, does    clear their
  1094.           memory and then report them as not defined anymore,
  1095.           but you shouldn't do that unless you don't plan to
  1096.           use them again, because it saves time    when you load
  1097.           them up again    to have    memory already ready to    be
  1098.           filled.  The normal way to free up space used    by an
  1099.           aggregate is to assign the empty list.
  1100.  
  1101.           This counterintuitive    behavior of defined() on
  1102.           aggregates may be changed, fixed, or broken in a
  1103.           future release of Perl.
  1104.  
  1105.           See also the undef, exists,  and ref entries
  1106.           elsewhere in this document.
  1107.  
  1108.       delete EXPR
  1109.           Deletes the specified    _k_e_y(s) and their associated
  1110.           values from a    hash.  For each    key, returns the
  1111.           deleted value    associated with    that key, or the
  1112.           undefined value if there was no such key.  Deleting
  1113.           from $ENV{} modifies the environment.     Deleting from
  1114.           a hash tied to a DBM file deletes the    entry from the
  1115.           DBM file.  (But deleting from    a tie()d hash doesn't
  1116.  
  1117.  
  1118.  
  1119.      Page 17                        (printed 10/23/98)
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1127.  
  1128.  
  1129.  
  1130.           necessarily return anything.)
  1131.  
  1132.           The following    deletes    all the    values of a hash:
  1133.  
  1134.               foreach $key (keys %HASH)    {
  1135.               delete $HASH{$key};
  1136.               }
  1137.  
  1138.           And so does this:
  1139.  
  1140.               delete @HASH{keys    %HASH}
  1141.  
  1142.           (But both of these are slower    than just assigning
  1143.           the empty list, or using undef().)  Note that    the
  1144.           EXPR can be arbitrarily complicated as long as the
  1145.           final    operation is a hash element lookup or hash
  1146.           slice:
  1147.  
  1148.               delete $ref->[$x][$y]{$key};
  1149.               delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys};
  1150.  
  1151.  
  1152.       die LIST
  1153.           Outside an eval(), prints the    value of LIST to
  1154.           STDERR and exits with    the current value of $!
  1155.           (errno).  If $! is 0,    exits with the value of    ($? >>
  1156.           8) (backtick `command` status).  If ($? >> 8)    is 0,
  1157.           exits    with 255.  Inside an eval(), the error message
  1158.           is stuffed into $@ and the eval() is terminated with
  1159.           the undefined    value.    This makes die() the way to
  1160.           raise    an exception.
  1161.  
  1162.           Equivalent examples:
  1163.  
  1164.               die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
  1165.               chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
  1166.  
  1167.           If the value of EXPR does not    end in a newline, the
  1168.           current script line number and input line number (if
  1169.           any) are also    printed, and a newline is supplied.
  1170.           Hint:    sometimes appending ", stopped"    to your
  1171.           message will cause it    to make    better sense when the
  1172.           string "at foo line 123" is appended.     Suppose you
  1173.           are running script "canasta".
  1174.  
  1175.               die "/etc/games is no good";
  1176.               die "/etc/games is no good, stopped";
  1177.  
  1178.           produce, respectively
  1179.  
  1180.               /etc/games is no good at canasta line 123.
  1181.               /etc/games is no good, stopped at    canasta    line 123.
  1182.  
  1183.  
  1184.  
  1185.      Page 18                        (printed 10/23/98)
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1193.  
  1194.  
  1195.  
  1196.           See also exit() and warn().
  1197.  
  1198.           If LIST is empty and $@ already contains a value
  1199.           (typically from a previous eval) that    value is
  1200.           reused after appending "\t...propagated".  This is
  1201.           useful for propagating exceptions:
  1202.  
  1203.               eval { ... };
  1204.               die unless $@ =~ /Expected exception/;
  1205.  
  1206.           If $@    is empty then the string "Died"    is used.
  1207.  
  1208.           You can arrange for a    callback to be run just    before
  1209.           the die() does its deed, by setting the
  1210.           $SIG{__DIE__}    hook.  The associated handler will be
  1211.           called with the error    text and can change the    error
  1212.           message, if it sees fit, by calling die() again.
  1213.           See the section on $_S_I_G{_e_x_p_r}    in the _p_e_r_l_v_a_r manpage
  1214.           for details on setting %SIG entries, and the section
  1215.           on _e_v_a_l _B_L_O_C_K    for some examples.
  1216.  
  1217.           Note that the    $SIG{__DIE__} hook is called even
  1218.           inside _e_v_a_l()ed blocks/strings.  If one wants    the
  1219.           hook to do nothing in    such situations, put
  1220.  
  1221.               die @_ if $^S;
  1222.  
  1223.           as the first line of the handler (see    the section on
  1224.           $^_S in the _p_e_r_l_v_a_r manpage).
  1225.  
  1226.       do BLOCK
  1227.           Not really a function.  Returns the value of the
  1228.           last command in the sequence of commands indicated
  1229.           by BLOCK.  When modified by a    loop modifier,
  1230.           executes the BLOCK once before testing the loop
  1231.           condition.  (On other    statements the loop modifiers
  1232.           test the conditional first.)
  1233.  
  1234.       do SUBROUTINE(LIST)
  1235.           A deprecated form of subroutine call.     See the
  1236.           _p_e_r_l_s_u_b manpage.
  1237.  
  1238.       do EXPR Uses the value of EXPR as a filename and executes
  1239.           the contents of the file as a    Perl script.  Its
  1240.           primary use is to include subroutines    from a Perl
  1241.           subroutine library.
  1242.  
  1243.               do 'stat.pl';
  1244.  
  1245.           is just like
  1246.  
  1247.               scalar eval `cat stat.pl`;
  1248.  
  1249.  
  1250.  
  1251.      Page 19                        (printed 10/23/98)
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1259.  
  1260.  
  1261.  
  1262.           except that it's more    efficient and concise, keeps
  1263.           track    of the current filename    for error messages,
  1264.           and searches all the ----IIII libraries if the file    isn't
  1265.           in the current directory (see    also the @INC array in
  1266.           the section on _P_r_e_d_e_f_i_n_e_d _N_a_m_e_s in the _p_e_r_l_v_a_r
  1267.           manpage).  It    is also    different in how code
  1268.           evaluated with do FILENAME doesn't see lexicals in
  1269.           the enclosing    scope like eval    STRING does.  It's the
  1270.           same,    however, in that it does reparse the file
  1271.           every    time you call it, so you probably don't    want
  1272.           to do    this inside a loop.
  1273.  
  1274.           If do    cannot read the    file, it returns undef and
  1275.           sets $! to the error.       If do can read the file but
  1276.           cannot compile it, it    returns    undef and sets an
  1277.           error    message    in $@.     If the    file is    successfully
  1278.           compiled, do returns the value of the    last
  1279.           expression evaluated.
  1280.  
  1281.           Note that inclusion of library modules is better
  1282.           done with the    use() and require() operators, which
  1283.           also do automatic error checking and raise an
  1284.           exception if there's a problem.
  1285.  
  1286.           You might like to use    do to read in a    program
  1287.           configuration    file.  Manual error checking can be
  1288.           done this way:
  1289.  
  1290.               #    read in    config files: system first, then user
  1291.               for $file    ("/share/prog/defaults.rc",
  1292.                  "$ENV{HOME}/.someprogrc") {
  1293.               unless ($return = do $file) {
  1294.                   warn "couldn't parse $file: $@" if $@;
  1295.                   warn "couldn't do    $file: $!"    unless defined $return;
  1296.                   warn "couldn't run $file"          unless $return;
  1297.               }
  1298.               }
  1299.  
  1300.  
  1301.       dump LABEL
  1302.           This causes an immediate core    dump.  Primarily this
  1303.           is so    that you can use the uuuunnnndddduuuummmmpppp program to turn
  1304.           your core dump into an executable binary after
  1305.           having initialized all your variables    at the
  1306.           beginning of the program.  When the new binary is
  1307.           executed it will begin by executing a    goto LABEL
  1308.           (with    all the    restrictions that goto suffers).
  1309.           Think    of it as a goto    with an    intervening core dump
  1310.           and reincarnation.  If LABEL is omitted, restarts
  1311.           the program from the top.  WARNING: Any files    opened
  1312.           at the time of the dump will NOT be open any more
  1313.           when the program is reincarnated, with possible
  1314.  
  1315.  
  1316.  
  1317.      Page 20                        (printed 10/23/98)
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1325.  
  1326.  
  1327.  
  1328.           resulting confusion on the part of Perl.  See    also
  1329.           ----uuuu option in the _p_e_r_l_r_u_n manpage.
  1330.  
  1331.           Example:
  1332.  
  1333.               #!/usr/bin/perl
  1334.               require 'getopt.pl';
  1335.               require 'stat.pl';
  1336.               %days = (
  1337.               'Sun'    => 1,
  1338.               'Mon'    => 2,
  1339.               'Tue'    => 3,
  1340.               'Wed'    => 4,
  1341.               'Thu'    => 5,
  1342.               'Fri'    => 6,
  1343.               'Sat'    => 7,
  1344.               );
  1345.  
  1346.               dump QUICKSTART if $ARGV[0] eq '-d';
  1347.  
  1348.               QUICKSTART:
  1349.               Getopt('f');
  1350.  
  1351.           This operator    is largely obsolete, partly because
  1352.           it's very hard to convert a core file    into an
  1353.           executable, and because the real perl-to-C compiler
  1354.           has superseded it.
  1355.  
  1356.       each HASH
  1357.           When called in list context, returns a 2-element
  1358.           list consisting of the key and value for the next
  1359.           element of a hash, so    that you can iterate over it.
  1360.           When called in scalar    context, returns the key for
  1361.           only the "next" element in the hash.    (Note: Keys
  1362.           may be "0" or    "", which are logically    false; you may
  1363.           wish to avoid    constructs like    while ($k = each %foo)
  1364.           {} for this reason.)
  1365.  
  1366.           Entries are returned in an apparently    random order.
  1367.           When the hash    is entirely read, a null array is
  1368.           returned in list context (which when assigned
  1369.           produces a FALSE (0) value), and undef in scalar
  1370.           context.  The    next call to each() after that will
  1371.           start    iterating again.  There    is a single iterator
  1372.           for each hash, shared    by all each(), keys(), and
  1373.           values() function calls in the program; it can be
  1374.           reset    by reading all the elements from the hash, or
  1375.           by evaluating    keys HASH or values HASH.  If you add
  1376.           or delete elements of    a hash while you're iterating
  1377.           over it, you may get entries skipped or duplicated,
  1378.           so don't.
  1379.  
  1380.  
  1381.  
  1382.  
  1383.      Page 21                        (printed 10/23/98)
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1391.  
  1392.  
  1393.  
  1394.           The following    prints out your    environment like the
  1395.           _p_r_i_n_t_e_n_v(1) program, only in a different order:
  1396.  
  1397.               while (($key,$value) = each %ENV)    {
  1398.               print    "$key=$value\n";
  1399.               }
  1400.  
  1401.           See also keys() and values().
  1402.  
  1403.       eof FILEHANDLE
  1404.  
  1405.       eof ()
  1406.  
  1407.       eof      Returns 1 if the next    read on    FILEHANDLE will    return
  1408.           end of file, or if FILEHANDLE    is not open.
  1409.           FILEHANDLE may be an expression whose    value gives
  1410.           the real filehandle.    (Note that this    function
  1411.           actually reads a character and then ungetc()s    it, so
  1412.           isn't    very useful in an interactive context.)     Do
  1413.           not read from    a terminal file    (or call
  1414.           eof(FILEHANDLE) on it) after end-of-file is reached.
  1415.           Filetypes such as terminals may lose the end-of-file
  1416.           condition if you do.
  1417.  
  1418.           An eof without an argument uses the last file    read
  1419.           as argument.    Using eof() with empty parentheses is
  1420.           very different.  It indicates    the pseudo file    formed
  1421.           of the files listed on the command line, i.e., eof()
  1422.           is reasonable    to use inside a    while (<>) loop    to
  1423.           detect the end of only the last file.     Use eof(ARGV)
  1424.           or eof without the parentheses to test _E_A_C_H file in
  1425.           a while (<>) loop.  Examples:
  1426.  
  1427.               #    reset line numbering on    each input file
  1428.               while (<>) {
  1429.               next if /^\s*#/;      # skip comments
  1430.               print    "$.\t$_";
  1431.               }    continue {
  1432.               close    ARGV  if eof;      # Not    eof()!
  1433.               }
  1434.  
  1435.               #    insert dashes just before last line of last file
  1436.               while (<>) {
  1437.               if (eof()) {          # check for end of current file
  1438.                   print "--------------\n";
  1439.                   close(ARGV);      # close or break; is needed if we
  1440.                           # are    reading    from the terminal
  1441.               }
  1442.               print;
  1443.               }
  1444.  
  1445.           Practical hint: you almost never need    to use eof in
  1446.  
  1447.  
  1448.  
  1449.      Page 22                        (printed 10/23/98)
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1457.  
  1458.  
  1459.  
  1460.           Perl,    because    the input operators return false
  1461.           values when they run out of data, or if there    was an
  1462.           error.
  1463.  
  1464.       eval EXPR
  1465.  
  1466.       eval BLOCK
  1467.           In the first form, the return    value of EXPR is
  1468.           parsed and executed as if it were a little Perl
  1469.           program.  The    value of the expression    (which is
  1470.           itself determined within scalar context) is first
  1471.           parsed, and if there weren't any errors, executed in
  1472.           the context of the current Perl program, so that any
  1473.           variable settings or subroutine and format
  1474.           definitions remain afterwards.  Note that the    value
  1475.           is parsed every time the eval    executes.  If EXPR is
  1476.           omitted, evaluates $_.  This form is typically used
  1477.           to delay parsing and subsequent execution of the
  1478.           text of EXPR until run time.
  1479.  
  1480.           In the second    form, the code within the BLOCK    is
  1481.           parsed only once--at the same    time the code
  1482.           surrounding the eval itself was parsed--and executed
  1483.           within the context of    the current Perl program.
  1484.           This form is typically used to trap exceptions more
  1485.           efficiently than the first (see below), while    also
  1486.           providing the    benefit    of checking the    code within
  1487.           BLOCK    at compile time.
  1488.  
  1489.           The final semicolon, if any, may be omitted from the
  1490.           value    of EXPR    or within the BLOCK.
  1491.  
  1492.           In both forms, the value returned is the value of
  1493.           the last expression evaluated    inside the mini-
  1494.           program; a return statement may be also used,    just
  1495.           as with subroutines.    The expression providing the
  1496.           return value is evaluated in void, scalar, or    list
  1497.           context, depending on    the context of the eval
  1498.           itself.  See the wantarray entry elsewhere in    this
  1499.           documentfor more on how the evaluation context can
  1500.           be determined.
  1501.  
  1502.           If there is a    syntax error or    runtime    error, or a
  1503.           die()    statement is executed, an undefined value is
  1504.           returned by eval(), and $@ is    set to the error
  1505.           message.  If there was no error, $@ is guaranteed to
  1506.           be a null string.  Beware that using eval() neither
  1507.           silences perl    from printing warnings to STDERR, nor
  1508.           does it stuff    the text of warning messages into $@.
  1509.           To do    either of those, you have to use the
  1510.           $SIG{__WARN__} facility.  See    the warn entry
  1511.           elsewhere in this document and the _p_e_r_l_v_a_r manpage.
  1512.  
  1513.  
  1514.  
  1515.      Page 23                        (printed 10/23/98)
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1523.  
  1524.  
  1525.  
  1526.           Note that, because eval() traps otherwise-fatal
  1527.           errors, it is    useful for determining whether a
  1528.           particular feature (such as socket() or symlink())
  1529.           is implemented.  It is also Perl's exception
  1530.           trapping mechanism, where the    die operator is    used
  1531.           to raise exceptions.
  1532.  
  1533.           If the code to be executed doesn't vary, you may use
  1534.           the eval-BLOCK form to trap run-time errors without
  1535.           incurring the    penalty    of recompiling each time.  The
  1536.           error, if any, is still returned in $@.  Examples:
  1537.  
  1538.               #    make divide-by-zero nonfatal
  1539.               eval { $answer = $a / $b;    }; warn    $@ if $@;
  1540.  
  1541.               #    same thing, but    less efficient
  1542.               eval '$answer = $a / $b';    warn $@    if $@;
  1543.  
  1544.               #    a compile-time error
  1545.               eval { $answer = };          # WRONG
  1546.  
  1547.               #    a run-time error
  1548.               eval '$answer =';      # sets $@
  1549.  
  1550.           When using the eval{}    form as    an exception trap in
  1551.           libraries, you may wish not to trigger any __DIE__
  1552.           hooks    that user code may have    installed.  You    can
  1553.           use the local    $SIG{__DIE__} construct    for this
  1554.           purpose, as shown in this example:
  1555.  
  1556.               #    a very private exception trap for divide-by-zero
  1557.               eval { local $SIG{'__DIE__'}; $answer = $a / $b; };
  1558.               warn $@ if $@;
  1559.  
  1560.           This is especially significant, given    that __DIE__
  1561.           hooks    can call die() again, which has    the effect of
  1562.           changing their error messages:
  1563.  
  1564.               #    __DIE__    hooks may modify error messages
  1565.               {
  1566.              local $SIG{'__DIE__'} =
  1567.                 sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };
  1568.              eval {    die "foo lives here" };
  1569.              print $@ if $@;        # prints "bar lives here"
  1570.               }
  1571.  
  1572.           With an eval(), you should be    especially careful to
  1573.           remember what's being    looked at when:
  1574.  
  1575.               eval $x;          # CASE 1
  1576.               eval "$x";      # CASE 2
  1577.  
  1578.  
  1579.  
  1580.  
  1581.      Page 24                        (printed 10/23/98)
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1589.  
  1590.  
  1591.  
  1592.               eval '$x';      # CASE 3
  1593.               eval { $x    };      # CASE 4
  1594.  
  1595.               eval "\$$x++";      # CASE 5
  1596.               $$x++;          # CASE 6
  1597.  
  1598.           Cases    1 and 2    above behave identically: they run the
  1599.           code contained in the    variable $x.  (Although    case 2
  1600.           has misleading double    quotes making the reader
  1601.           wonder what else might be happening (nothing is).)
  1602.           Cases    3 and 4    likewise behave    in the same way: they
  1603.           run the code '$x', which does    nothing    but return the
  1604.           value    of $x.    (Case 4    is preferred for purely    visual
  1605.           reasons, but it also has the advantage of compiling
  1606.           at compile-time instead of at    run-time.)  Case 5 is
  1607.           a place where    normally you _W_O_U_L_D like    to use double
  1608.           quotes, except that in this particular situation,
  1609.           you can just use symbolic references instead,    as in
  1610.           case 6.
  1611.  
  1612.       exec LIST
  1613.  
  1614.       exec PROGRAM LIST
  1615.           The exec() function executes a system    command    _A_N_D
  1616.           _N_E_V_E_R    _R_E_T_U_R_N_S    - use system() instead of exec() if
  1617.           you want it to return. It fails and returns FALSE
  1618.           only if the command does not exist _a_n_d it is
  1619.           executed directly instead of via your    system's
  1620.           command shell    (see below).
  1621.  
  1622.           Since    it's a common mistake to use exec() instead of
  1623.           system(), Perl warns you if there is a following
  1624.           statement which isn't    die(), warn(), or exit() (if
  1625.           -w is    set  -    but you    always do that).   If you
  1626.           _r_e_a_l_l_y want to follow    an exec() with some other
  1627.           statement, you can use one of    these styles to    avoid
  1628.           the warning:
  1629.  
  1630.               exec ('foo')   or    print STDERR "couldn't exec foo: $!";
  1631.               {    exec ('foo') };    print STDERR "couldn't exec foo: $!";
  1632.  
  1633.           If there is more than    one argument in    LIST, or if
  1634.           LIST is an array with    more than one value, calls
  1635.           _e_x_e_c_v_p(3) with the arguments in LIST.     If there is
  1636.           only one scalar argument or an array with one
  1637.           element in it, the argument is checked for shell
  1638.           metacharacters, and if there are any,    the entire
  1639.           argument is passed to    the system's command shell for
  1640.           parsing (this    is /bin/sh -c on Unix platforms, but
  1641.           varies on other platforms).  If there    are no shell
  1642.           metacharacters in the    argument, it is    split into
  1643.           words    and passed directly to execvp(), which is more
  1644.  
  1645.  
  1646.  
  1647.      Page 25                        (printed 10/23/98)
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1655.  
  1656.  
  1657.  
  1658.           efficient.  Note:  exec() and    system() do not    flush
  1659.           your output buffer, so you may need to set $|    to
  1660.           avoid    lost output.  Examples:
  1661.  
  1662.               exec '/bin/echo',    'Your arguments    are: ',    @ARGV;
  1663.               exec "sort $outfile | uniq";
  1664.  
  1665.           If you don't really want to execute the first
  1666.           argument, but    want to    lie to the program you are
  1667.           executing about its own name,    you can    specify    the
  1668.           program you actually want to run as an "indirect
  1669.           object" (without a comma) in front of    the LIST.
  1670.           (This    always forces interpretation of    the LIST as a
  1671.           multivalued list, even if there is only a single
  1672.           scalar in the    list.)    Example:
  1673.  
  1674.               $shell = '/bin/csh';
  1675.               exec $shell '-sh';      # pretend it's a login shell
  1676.  
  1677.           or, more directly,
  1678.  
  1679.               exec {'/bin/csh'}    '-sh';      # pretend it's a login shell
  1680.  
  1681.           When the arguments get executed via the system
  1682.           shell, results will be subject to its    quirks and
  1683.           capabilities.     See the section on `_S_T_R_I_N_G` in    the
  1684.           _p_e_r_l_o_p manpage for details.
  1685.  
  1686.           Using    an indirect object with    exec() or system() is
  1687.           also more secure.  This usage    forces interpretation
  1688.           of the arguments as a    multivalued list, even if the
  1689.           list had just    one argument.  That way    you're safe
  1690.           from the shell expanding wildcards or    splitting up
  1691.           words    with whitespace    in them.
  1692.  
  1693.               @args = (    "echo surprise"    );
  1694.  
  1695.               system @args;          # subject to shell escapes
  1696.                           # if @args ==    1
  1697.               system { $args[0]    } @args;  # safe even with one-arg list
  1698.  
  1699.           The first version, the one without the indirect
  1700.           object, ran the _e_c_h_o program,    passing    it "surprise"
  1701.           an argument.    The second version didn't--it tried to
  1702.           run a    program    literally called "_e_c_h_o _s_u_r_p_r_i_s_e",
  1703.           didn't find it, and set $? to    a non-zero value
  1704.           indicating failure.
  1705.  
  1706.           Note that exec() will    not call your END blocks, nor
  1707.           will it call any DESTROY methods in your objects.
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.      Page 26                        (printed 10/23/98)
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1721.  
  1722.  
  1723.  
  1724.       exists EXPR
  1725.           Returns TRUE if the specified    hash key exists    in its
  1726.           hash array, even if the corresponding    value is
  1727.           undefined.
  1728.  
  1729.               print "Exists\n" if exists $array{$key};
  1730.               print "Defined\n"    if defined $array{$key};
  1731.               print "True\n" if    $array{$key};
  1732.  
  1733.           A hash element can be    TRUE only if it's defined, and
  1734.           defined if it    exists,    but the    reverse    doesn't
  1735.           necessarily hold true.
  1736.  
  1737.           Note that the    EXPR can be arbitrarily    complicated as
  1738.           long as the final operation is a hash    key lookup:
  1739.  
  1740.               if (exists $ref->{"A"}{"B"}{$key}) { ... }
  1741.  
  1742.           Although the last element will not spring into
  1743.           existence just because its existence was tested,
  1744.           intervening ones will.  Thus $ref->{"A"} $ref->{"B"}
  1745.           will spring into existence due to the    existence test
  1746.           for a    $key element.  This autovivification may be
  1747.           fixed    in a later release.
  1748.  
  1749.       exit EXPR
  1750.           Evaluates EXPR and exits immediately with that
  1751.           value.  (Actually, it    calls any defined END routines
  1752.           first, but the END routines may not abort the    exit.
  1753.           Likewise any object destructors that need to be
  1754.           called are called before exit.)  Example:
  1755.  
  1756.               $ans = <STDIN>;
  1757.               exit 0 if    $ans =~    /^[Xx]/;
  1758.  
  1759.           See also die().  If EXPR is omitted, exits with 0
  1760.           status.  The only universally    portable values    for
  1761.           EXPR are 0 for success and 1 for error; all other
  1762.           values are subject to    unpredictable interpretation
  1763.           depending on the environment in which    the Perl
  1764.           program is running.
  1765.  
  1766.           You shouldn't    use exit() to abort a subroutine if
  1767.           there's any chance that someone might    want to    trap
  1768.           whatever error happened.  Use    die() instead, which
  1769.           can be trapped by an eval().
  1770.  
  1771.           All END{} blocks are run at exit time.  See the
  1772.           _p_e_r_l_s_u_b manpage for details.
  1773.  
  1774.       exp EXPR
  1775.  
  1776.  
  1777.  
  1778.  
  1779.      Page 27                        (printed 10/23/98)
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1787.  
  1788.  
  1789.  
  1790.       exp      Returns _e (the natural logarithm base) to the    power
  1791.           of EXPR.  If EXPR is omitted,    gives exp($_).
  1792.  
  1793.       fcntl    FILEHANDLE,FUNCTION,SCALAR
  1794.           Implements the _f_c_n_t_l(2) function.  You'll probably
  1795.           have to say
  1796.  
  1797.               use Fcntl;
  1798.  
  1799.           first    to get the correct constant definitions.
  1800.           Argument processing and value    return works just like
  1801.           ioctl() below. For example:
  1802.  
  1803.               use Fcntl;
  1804.               fcntl($filehandle, F_GETFL, $packed_return_buffer)
  1805.               or die "can't    fcntl F_GETFL: $!";
  1806.  
  1807.           You don't have to check for defined()    on the return
  1808.           from fnctl().     Like ioctl(), it maps a 0 return from
  1809.           the system call into "0 but true" in Perl.  This
  1810.           string is true in boolean context and    0 in numeric
  1811.           context.  It is also exempt from the normal ----wwww
  1812.           warnings on improper numeric conversions.
  1813.  
  1814.           Note that fcntl() will produce a fatal error if used
  1815.           on a machine that doesn't implement _f_c_n_t_l(2).
  1816.  
  1817.       fileno FILEHANDLE
  1818.           Returns the file descriptor for a filehandle.     This
  1819.           is useful for    constructing bitmaps for select() and
  1820.           low-level POSIX tty-handling operations.  If
  1821.           FILEHANDLE is    an expression, the value is taken as
  1822.           an indirect filehandle, generally its    name.
  1823.  
  1824.           You can use this to find out whether two handles
  1825.           refer    to the same underlying descriptor:
  1826.  
  1827.               if (fileno(THIS) == fileno(THAT))    {
  1828.               print    "THIS and THAT are dups\n";
  1829.               }
  1830.  
  1831.  
  1832.       flock    FILEHANDLE,OPERATION
  1833.           Calls    _f_l_o_c_k(2), or an    emulation of it, on
  1834.           FILEHANDLE.  Returns TRUE for    success, FALSE on
  1835.           failure.  Produces a fatal error if used on a
  1836.           machine that doesn't implement _f_l_o_c_k(2), _f_c_n_t_l(2)
  1837.           locking, or _l_o_c_k_f(3).     flock() is Perl's portable
  1838.           file locking interface, although it locks only
  1839.           entire files,    not records.
  1840.  
  1841.           On many platforms (including most versions or    clones
  1842.  
  1843.  
  1844.  
  1845.      Page 28                        (printed 10/23/98)
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1853.  
  1854.  
  1855.  
  1856.           of Unix), locks established by flock() are mmmmeeeerrrreeeellllyyyy
  1857.           aaaaddddvvvviiiissssoooorrrryyyy.  Such discretionary    locks are more
  1858.           flexible, but    offer fewer guarantees.     This means
  1859.           that files locked with flock() may be    modified by
  1860.           programs that    do not also use    flock().  Windows NT
  1861.           and OS/2 are among the platforms which enforce
  1862.           mandatory locking.  See your local documentation for
  1863.           details.
  1864.  
  1865.           OPERATION is one of LOCK_SH, LOCK_EX,    or LOCK_UN,
  1866.           possibly combined with LOCK_NB.  These constants are
  1867.           traditionally    valued 1, 2, 8 and 4, but you can use
  1868.           the symbolic names if    import them from the Fcntl
  1869.           module, either individually, or as a group using the
  1870.           ':flock' tag.     LOCK_SH requests a shared lock,
  1871.           LOCK_EX requests an exclusive    lock, and LOCK_UN
  1872.           releases a previously    requested lock.     If LOCK_NB is
  1873.           added    to LOCK_SH or LOCK_EX then flock() will    return
  1874.           immediately rather than blocking waiting for the
  1875.           lock (check the return status    to see if you got it).
  1876.  
  1877.           To avoid the possibility of mis-coordination,    Perl
  1878.           flushes FILEHANDLE before (un)locking    it.
  1879.  
  1880.           Note that the    emulation built    with _l_o_c_k_f(3) doesn't
  1881.           provide shared locks,    and it requires    that
  1882.           FILEHANDLE be    open with write    intent.     These are the
  1883.           semantics that _l_o_c_k_f(3) implements.  Most (all?)
  1884.           systems implement _l_o_c_k_f(3) in    terms of _f_c_n_t_l(2)
  1885.           locking, though, so the differing semantics
  1886.           shouldn't bite too many people.
  1887.  
  1888.           Note also that some versions of flock() cannot lock
  1889.           things over the network; you would need to use the
  1890.           more system-specific fcntl() for that.  If you like
  1891.           you can force    Perl to    ignore your system's _f_l_o_c_k(2)
  1892.           function, and    so provide its own _f_c_n_t_l(2)-based
  1893.           emulation, by    passing    the switch -Ud_flock to    the
  1894.           _C_o_n_f_i_g_u_r_e program when you configure perl.
  1895.  
  1896.           Here's a mailbox appender for    BSD systems.
  1897.  
  1898.               use Fcntl    ':flock'; # import LOCK_* constants
  1899.  
  1900.               sub lock {
  1901.               flock(MBOX,LOCK_EX);
  1902.               # and, in case someone appended
  1903.               # while we were waiting...
  1904.               seek(MBOX, 0,    2);
  1905.               }
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.      Page 29                        (printed 10/23/98)
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1919.  
  1920.  
  1921.  
  1922.               sub unlock {
  1923.               flock(MBOX,LOCK_UN);
  1924.               }
  1925.  
  1926.               open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
  1927.                   or die "Can't open mailbox: $!";
  1928.  
  1929.               lock();
  1930.               print MBOX $msg,"\n\n";
  1931.               unlock();
  1932.  
  1933.           See also the _D_B__F_i_l_e manpage for other _f_l_o_c_k()
  1934.           examples.
  1935.  
  1936.       fork      Does a _f_o_r_k(2) system    call.  Returns the child pid
  1937.           to the parent    process, 0 to the child    process, or
  1938.           undef    if the fork is unsuccessful.
  1939.  
  1940.           Note:    unflushed buffers remain unflushed in both
  1941.           processes, which means you may need to set $|
  1942.           ($AUTOFLUSH in English) or call the autoflush()
  1943.           method of IO::Handle to avoid    duplicate output.
  1944.  
  1945.           If you fork()    without    ever waiting on    your children,
  1946.           you will accumulate zombies:
  1947.  
  1948.               $SIG{CHLD} = sub { wait };
  1949.  
  1950.           There's also the double-fork trick (error checking
  1951.           on fork() returns omitted);
  1952.  
  1953.               unless ($pid = fork) {
  1954.               unless (fork)    {
  1955.                   exec "what you really wanna do";
  1956.                   die "no exec";
  1957.                   #    ... or ...
  1958.                   ## (some_perl_code_here)
  1959.                   exit 0;
  1960.               }
  1961.               exit 0;
  1962.               }
  1963.               waitpid($pid,0);
  1964.  
  1965.           See also the _p_e_r_l_i_p_c manpage for more    examples of
  1966.           forking and reaping moribund children.
  1967.  
  1968.           Note that if your forked child inherits system file
  1969.           descriptors like STDIN and STDOUT that are actually
  1970.           connected by a pipe or socket, even if you exit,
  1971.           then the remote server (such as, say,    httpd or rsh)
  1972.           won't    think you're done.  You    should reopen those to
  1973.           /_d_e_v/_n_u_l_l if it's any    issue.
  1974.  
  1975.  
  1976.  
  1977.      Page 30                        (printed 10/23/98)
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1985.  
  1986.  
  1987.  
  1988.       format  Declare a picture format for use by the write()
  1989.           function.  For example:
  1990.  
  1991.               format Something =
  1992.               Test:    @<<<<<<<< @||||| @>>>>>
  1993.                 $str,      $%,     '$' . int($num)
  1994.               .
  1995.  
  1996.               $str = "widget";
  1997.               $num = $cost/$quantity;
  1998.               $~ = 'Something';
  1999.               write;
  2000.  
  2001.           See the _p_e_r_l_f_o_r_m manpage for many details and
  2002.           examples.
  2003.  
  2004.       formline PICTURE,LIST
  2005.           This is an internal function used by formats,    though
  2006.           you may call it, too.     It formats (see the _p_e_r_l_f_o_r_m
  2007.           manpage) a list of values according to the contents
  2008.           of PICTURE, placing the output into the format
  2009.           output accumulator, $^A (or $ACCUMULATOR in
  2010.           English).  Eventually, when a    write()    is done, the
  2011.           contents of $^A are written to some filehandle, but
  2012.           you could also read $^A yourself and then set    $^A
  2013.           back to "".  Note that a format typically does one
  2014.           formline() per line of form, but the formline()
  2015.           function itself doesn't care how many    newlines are
  2016.           embedded in the PICTURE.  This means that the    ~ and
  2017.           ~~ tokens will treat the entire PICTURE as a single
  2018.           line.     You may therefore need    to use multiple
  2019.           formlines to implement a single record format, just
  2020.           like the format compiler.
  2021.  
  2022.           Be careful if    you put    double quotes around the
  2023.           picture, because an "@" character may    be taken to
  2024.           mean the beginning of    an array name.    formline()
  2025.           always returns TRUE.    See the    _p_e_r_l_f_o_r_m manpage for
  2026.           other    examples.
  2027.  
  2028.       getc FILEHANDLE
  2029.  
  2030.       getc      Returns the next character from the input file
  2031.           attached to FILEHANDLE, or the undefined value at
  2032.           end of file, or if there was an error.  If
  2033.           FILEHANDLE is    omitted, reads from STDIN.  This is
  2034.           not particularly efficient.  It cannot be used to
  2035.           get unbuffered single-characters, however.  For
  2036.           that,    try something more like:
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.      Page 31                        (printed 10/23/98)
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2051.  
  2052.  
  2053.  
  2054.               if ($BSD_STYLE) {
  2055.               system "stty cbreak </dev/tty    >/dev/tty 2>&1";
  2056.               }
  2057.               else {
  2058.               system "stty", '-icanon', 'eol', "\001";
  2059.               }
  2060.  
  2061.               $key = getc(STDIN);
  2062.  
  2063.               if ($BSD_STYLE) {
  2064.               system "stty -cbreak </dev/tty >/dev/tty 2>&1";
  2065.               }
  2066.               else {
  2067.               system "stty", 'icanon', 'eol', '^@';    # ASCII    null
  2068.               }
  2069.               print "\n";
  2070.  
  2071.           Determination    of whether $BSD_STYLE should be    set is
  2072.           left as an exercise to the reader.
  2073.  
  2074.           The POSIX::getattr() function    can do this more
  2075.           portably on systems purporting POSIX compliance.
  2076.           See also the Term::ReadKey module from your nearest
  2077.           CPAN site; details on    CPAN can be found on the CPAN
  2078.           entry    in the _p_e_r_l_m_o_d manpage.
  2079.  
  2080.       getlogin
  2081.           Implements the C library function of the same    name,
  2082.           which    on most    systems    returns    the current login from
  2083.           /_e_t_c/_u_t_m_p, if    any.  If null, use getpwuid().
  2084.  
  2085.               $login = getlogin    || getpwuid($<)    || "Kilroy";
  2086.  
  2087.           Do not consider getlogin() for authentication: it is
  2088.           not as secure    as getpwuid().
  2089.  
  2090.       getpeername SOCKET
  2091.           Returns the packed sockaddr address of other end of
  2092.           the SOCKET connection.
  2093.  
  2094.               use Socket;
  2095.               $hersockaddr    =    getpeername(SOCK);
  2096.               ($port, $iaddr) =    unpack_sockaddr_in($hersockaddr);
  2097.               $herhostname    =    gethostbyaddr($iaddr, AF_INET);
  2098.               $herstraddr     =    inet_ntoa($iaddr);
  2099.  
  2100.  
  2101.       getpgrp PID
  2102.           Returns the current process group for    the specified
  2103.           PID.    Use a PID of 0 to get the current process
  2104.           group    for the    current    process.  Will raise an
  2105.           exception if used on a machine that doesn't
  2106.  
  2107.  
  2108.  
  2109.      Page 32                        (printed 10/23/98)
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2117.  
  2118.  
  2119.  
  2120.           implement _g_e_t_p_g_r_p(2).     If PID    is omitted, returns
  2121.           process group    of current process.  Note that the
  2122.           POSIX    version    of getpgrp() does not accept a PID
  2123.           argument, so only PID==0 is truly portable.
  2124.  
  2125.       getppid Returns the process id of the    parent process.
  2126.  
  2127.       getpriority WHICH,WHO
  2128.           Returns the current priority for a process, a
  2129.           process group, or a user.  (See the _g_e_t_p_r_i_o_r_i_t_y(_2)
  2130.           manpage.)  Will raise    a fatal    exception if used on a
  2131.           machine that doesn't implement _g_e_t_p_r_i_o_r_i_t_y(2).
  2132.  
  2133.       getpwnam NAME
  2134.  
  2135.       getgrnam NAME
  2136.  
  2137.       gethostbyname    NAME
  2138.  
  2139.       getnetbyname NAME
  2140.  
  2141.       getprotobyname NAME
  2142.  
  2143.       getpwuid UID
  2144.  
  2145.       getgrgid GID
  2146.  
  2147.       getservbyname    NAME,PROTO
  2148.  
  2149.       gethostbyaddr    ADDR,ADDRTYPE
  2150.  
  2151.       getnetbyaddr ADDR,ADDRTYPE
  2152.  
  2153.       getprotobynumber NUMBER
  2154.  
  2155.       getservbyport    PORT,PROTO
  2156.  
  2157.       getpwent
  2158.  
  2159.       getgrent
  2160.  
  2161.       gethostent
  2162.  
  2163.       getnetent
  2164.  
  2165.       getprotoent
  2166.  
  2167.       getservent
  2168.  
  2169.       setpwent
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.      Page 33                        (printed 10/23/98)
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2183.  
  2184.  
  2185.  
  2186.       setgrent
  2187.  
  2188.       sethostent STAYOPEN
  2189.  
  2190.       setnetent STAYOPEN
  2191.  
  2192.       setprotoent STAYOPEN
  2193.  
  2194.       setservent STAYOPEN
  2195.  
  2196.       endpwent
  2197.  
  2198.       endgrent
  2199.  
  2200.       endhostent
  2201.  
  2202.       endnetent
  2203.  
  2204.       endprotoent
  2205.  
  2206.       endservent
  2207.           These    routines perform the same functions as their
  2208.           counterparts in the system library.  In list
  2209.           context, the return values from the various get
  2210.           routines are as follows:
  2211.  
  2212.               ($name,$passwd,$uid,$gid,
  2213.              $quota,$comment,$gcos,$dir,$shell,$expire) = getpw*
  2214.               ($name,$passwd,$gid,$members) = getgr*
  2215.               ($name,$aliases,$addrtype,$length,@addrs)    = gethost*
  2216.               ($name,$aliases,$addrtype,$net) =    getnet*
  2217.               ($name,$aliases,$proto) =    getproto*
  2218.               ($name,$aliases,$port,$proto) = getserv*
  2219.  
  2220.           (If the entry    doesn't    exist you get a    null list.)
  2221.  
  2222.           In scalar context, you get the name, unless the
  2223.           function was a lookup    by name, in which case you get
  2224.           the other thing, whatever it is.  (If    the entry
  2225.           doesn't exist    you get    the undefined value.)  For
  2226.           example:
  2227.  
  2228.               $uid   = getpwnam($name);
  2229.               $name  = getpwuid($num);
  2230.               $name  = getpwent();
  2231.               $gid   = getgrnam($name);
  2232.               $name  = getgrgid($num;
  2233.               $name  = getgrent();
  2234.               #etc.
  2235.  
  2236.           In _g_e_t_p_w*() the fields $quota, $comment, and $expire
  2237.           are special cases in the sense that in many systems
  2238.  
  2239.  
  2240.  
  2241.      Page 34                        (printed 10/23/98)
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2249.  
  2250.  
  2251.  
  2252.           they are unsupported.     If the    $quota is unsupported,
  2253.           it is    an empty scalar.  If it    is supported, it
  2254.           usually encodes the disk quota.  If the $comment
  2255.           field    is unsupported,    it is an empty scalar.    If it
  2256.           is supported it usually encodes some administrative
  2257.           comment about    the user.  In some systems the $quota
  2258.           field    may be $change or $age,    fields that have to do
  2259.           with password    aging.    In some    systems    the $comment
  2260.           field    may be $class.    The $expire field, if present,
  2261.           encodes the expiration period    of the account or the
  2262.           password.  For the availability and the exact
  2263.           meaning of these fields in your system, please
  2264.           consult your _g_e_t_p_w_n_a_m(3) documentation and your
  2265.           _p_w_d._h    file.  You can also find out from within Perl
  2266.           which    meaning    your $quota and    $comment fields    have
  2267.           and whether you have the $expire field by using the
  2268.           Config module    and the    values d_pwquota, d_pwage,
  2269.           d_pwchange, d_pwcomment, and d_pwexpire.
  2270.  
  2271.           The $members value returned by _g_e_t_g_r*() is a space
  2272.           separated list of the    login names of the members of
  2273.           the group.
  2274.  
  2275.           For the _g_e_t_h_o_s_t*() functions,    if the h_errno
  2276.           variable is supported    in C, it will be returned to
  2277.           you via $? if    the function call fails.  The @addrs
  2278.           value    returned by a successful call is a list    of the
  2279.           raw addresses    returned by the    corresponding system
  2280.           library call.     In the    Internet domain, each address
  2281.           is four bytes    long and you can unpack    it by saying
  2282.           something like:
  2283.  
  2284.               ($a,$b,$c,$d) = unpack('C4',$addr[0]);
  2285.  
  2286.           If you get tired of remembering which    element    of the
  2287.           return list contains which return value, by-name
  2288.           interfaces are also provided in modules:
  2289.           File::stat, Net::hostent, Net::netent,
  2290.           Net::protoent, Net::servent, Time::gmtime,
  2291.           Time::localtime, and User::grent.  These override
  2292.           the normal built-in, replacing them with versions
  2293.           that return objects with the appropriate names for
  2294.           each field.  For example:
  2295.  
  2296.              use File::stat;
  2297.              use User::pwent;
  2298.              $is_his = (stat($filename)->uid ==    pwent($whoever)->uid);
  2299.  
  2300.           Even though it looks like they're the    same method
  2301.           calls    (uid), they aren't, because a File::stat
  2302.           object is different from a User::pwent object.
  2303.  
  2304.  
  2305.  
  2306.  
  2307.      Page 35                        (printed 10/23/98)
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2315.  
  2316.  
  2317.  
  2318.       getsockname SOCKET
  2319.           Returns the packed sockaddr address of this end of
  2320.           the SOCKET connection.
  2321.  
  2322.               use Socket;
  2323.               $mysockaddr = getsockname(SOCK);
  2324.               ($port, $myaddr) = unpack_sockaddr_in($mysockaddr);
  2325.  
  2326.  
  2327.       getsockopt SOCKET,LEVEL,OPTNAME
  2328.           Returns the socket option requested, or undef    if
  2329.           there    is an error.
  2330.  
  2331.       glob EXPR
  2332.  
  2333.       glob      Returns the value of EXPR with filename expansions
  2334.           such as the standard Unix shell /_b_i_n/_s_h would    do.
  2335.           This is the internal function    implementing the <*.c>
  2336.           operator, but    you can    use it directly.  If EXPR is
  2337.           omitted, $_ is used.    The <*.c> operator is
  2338.           discussed in more detail in the section on _I/_O
  2339.           _O_p_e_r_a_t_o_r_s in the _p_e_r_l_o_p manpage.
  2340.  
  2341.       gmtime EXPR
  2342.           Converts a time as returned by the time function to
  2343.           a 9-element array with the time localized for    the
  2344.           standard Greenwich time zone.     Typically used    as
  2345.           follows:
  2346.  
  2347.               #     0    1       2     3     4    5      6    7     8
  2348.               ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  2349.                                   gmtime(time);
  2350.  
  2351.           All array elements are numeric, and come straight
  2352.           out of a struct tm.  In particular this means    that
  2353.           $mon has the range 0..11 and $wday has the range
  2354.           0..6 with sunday as day 0.  Also, $year is the
  2355.           number of years since    1900, that is, $year is    123 in
  2356.           year 2023, _n_o_t simply    the last two digits of the
  2357.           year.
  2358.  
  2359.           If EXPR is omitted, does gmtime(time()).
  2360.  
  2361.           In scalar context, returns the _c_t_i_m_e(3) value:
  2362.  
  2363.               $now_string = gmtime;  # e.g., "Thu Oct 13 04:54:34 1994"
  2364.  
  2365.           Also see the timegm()    function provided by the
  2366.           Time::Local module, and the _s_t_r_f_t_i_m_e(3) function
  2367.           available via    the POSIX module.
  2368.  
  2369.           This scalar value is nnnnooootttt locale dependent, see the
  2370.  
  2371.  
  2372.  
  2373.      Page 36                        (printed 10/23/98)
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2381.  
  2382.  
  2383.  
  2384.           _p_e_r_l_l_o_c_a_l_e manpage, but instead a Perl builtin.
  2385.           Also see the Time::Local module, and the _s_t_r_f_t_i_m_e(3)
  2386.           and _m_k_t_i_m_e(3)    function available via the POSIX
  2387.           module.  To get somewhat similar but locale
  2388.           dependent date strings, set up your locale
  2389.           environment variables    appropriately (please see the
  2390.           _p_e_r_l_l_o_c_a_l_e manpage) and try for example:
  2391.  
  2392.               use POSIX    qw(strftime);
  2393.               $now_string =    strftime "%a %b    %e %H:%M:%S %Y", gmtime;
  2394.  
  2395.           Note that the    %a and %b, the short forms of the day
  2396.           of the week and the month of the year, may not
  2397.           necessarily be three characters wide.
  2398.  
  2399.       goto LABEL
  2400.  
  2401.       goto EXPR
  2402.  
  2403.       goto &NAME
  2404.           The goto-LABEL form finds the    statement labeled with
  2405.           LABEL    and resumes execution there.  It may not be
  2406.           used to go into any construct    that requires
  2407.           initialization, such as a subroutine or a foreach
  2408.           loop.     It also can't be used to go into a construct
  2409.           that is optimized away, or to    get out    of a block or
  2410.           subroutine given to sort().  It can be used to go
  2411.           almost anywhere else within the dynamic scope,
  2412.           including out    of subroutines,    but it's usually
  2413.           better to use    some other construct such as last or
  2414.           die().  The author of    Perl has never felt the    need
  2415.           to use this form of goto (in Perl, that is--C    is
  2416.           another matter).
  2417.  
  2418.           The goto-EXPR    form expects a label name, whose scope
  2419.           will be resolved dynamically.     This allows for
  2420.           computed gotos per FORTRAN, but isn't    necessarily
  2421.           recommended if you're    optimizing for
  2422.           maintainability:
  2423.  
  2424.               goto ("FOO", "BAR", "GLARCH")[$i];
  2425.  
  2426.           The goto-&NAME form is highly    magical, and
  2427.           substitutes a    call to    the named subroutine for the
  2428.           currently running subroutine.     This is used by
  2429.           AUTOLOAD subroutines that wish to load another
  2430.           subroutine and then pretend that the other
  2431.           subroutine had been called in    the first place
  2432.           (except that any modifications to @_ in the current
  2433.           subroutine are propagated to the other subroutine.)
  2434.           After    the goto, not even caller() will be able to
  2435.           tell that this routine was called first.
  2436.  
  2437.  
  2438.  
  2439.      Page 37                        (printed 10/23/98)
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2447.  
  2448.  
  2449.  
  2450.       grep BLOCK LIST
  2451.  
  2452.       grep EXPR,LIST
  2453.           This is similar in spirit to,    but not    the same as,
  2454.           _g_r_e_p(1) and its relatives.  In particular, it    is not
  2455.           limited to using regular expressions.
  2456.  
  2457.           Evaluates the    BLOCK or EXPR for each element of LIST
  2458.           (locally setting $_ to each element) and returns the
  2459.           list value consisting    of those elements for which
  2460.           the expression evaluated to TRUE.  In    a scalar
  2461.           context, returns the number of times the expression
  2462.           was TRUE.
  2463.  
  2464.               @foo = grep(!/^#/, @bar);       # weed out comments
  2465.  
  2466.           or equivalently,
  2467.  
  2468.               @foo = grep {!/^#/} @bar;       # weed out comments
  2469.  
  2470.           Note that, because $_    is a reference into the    list
  2471.           value, it can    be used    to modify the elements of the
  2472.           array.  While    this is    useful and supported, it can
  2473.           cause    bizarre    results    if the LIST is not a named
  2474.           array.  Similarly, grep returns aliases into the
  2475.           original list, much like the way that    a for loop's
  2476.           index    variable aliases the list elements.  That is,
  2477.           modifying an element of a list returned by grep (for
  2478.           example, in a    foreach, map() or another grep())
  2479.           actually modifies the    element    in the original    list.
  2480.  
  2481.           See also the map entry elsewhere in this documentfor
  2482.           an array composed of the results of the BLOCK    or
  2483.           EXPR.
  2484.  
  2485.       hex EXPR
  2486.  
  2487.       hex      Interprets EXPR as a hex string and returns the
  2488.           corresponding    value.    (To convert strings that might
  2489.           start    with either 0 or 0x see    the oct    entry
  2490.           elsewhere in this document.)    If EXPR    is omitted,
  2491.           uses $_.
  2492.  
  2493.               print hex    '0xAf';    # prints '175'
  2494.               print hex    'aF';    # same
  2495.  
  2496.  
  2497.       import  There    is no builtin import() function.  It is    just
  2498.           an ordinary method (subroutine) defined (or
  2499.           inherited) by    modules    that wish to export names to
  2500.           another module.  The use() function calls the
  2501.           import() method for the package used.     See also the
  2502.  
  2503.  
  2504.  
  2505.      Page 38                        (printed 10/23/98)
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2513.  
  2514.  
  2515.  
  2516.           use()    entry elsewhere    in this    documentthe _p_e_r_l_m_o_d
  2517.           manpage, and the _E_x_p_o_r_t_e_r manpage.
  2518.  
  2519.       index    STR,SUBSTR,POSITION
  2520.  
  2521.       index    STR,SUBSTR
  2522.           Returns the position of the first occurrence of
  2523.           SUBSTR in STR    at or after POSITION.  If POSITION is
  2524.           omitted, starts searching from the beginning of the
  2525.           string.  The return value is based at    0 (or whatever
  2526.           you've set the $[ variable to--but don't do that).
  2527.           If the substring is not found, returns one less than
  2528.           the base, ordinarily -1.
  2529.  
  2530.       int EXPR
  2531.  
  2532.       int      Returns the integer portion of EXPR.    If EXPR    is
  2533.           omitted, uses    $_.  You should    not use    this for
  2534.           rounding, because it truncates towards 0, and
  2535.           because machine representations of floating point
  2536.           numbers can sometimes    produce    counterintuitive
  2537.           results.  Usually sprintf() or printf(), or the
  2538.           POSIX::floor or POSIX::ceil functions, would serve
  2539.           you better.
  2540.  
  2541.       ioctl    FILEHANDLE,FUNCTION,SCALAR
  2542.           Implements the _i_o_c_t_l(2) function.  You'll probably
  2543.           have to say
  2544.  
  2545.               require "ioctl.ph"; # probably in    /usr/local/lib/perl/ioctl.ph
  2546.  
  2547.           first    to get the correct function definitions.  If
  2548.           _i_o_c_t_l._p_h doesn't exist or doesn't have the correct
  2549.           definitions you'll have to roll your own, based on
  2550.           your C header    files such as <_s_y_s/_i_o_c_t_l._h>.  (There
  2551.           is a Perl script called hhhh2222pppphhhh that comes with the
  2552.           Perl kit that    may help you in    this, but it's
  2553.           nontrivial.)    SCALAR will be read and/or written
  2554.           depending on the FUNCTION--a pointer to the string
  2555.           value    of SCALAR will be passed as the    third argument
  2556.           of the actual    ioctl()    call.  (If SCALAR has no
  2557.           string value but does    have a numeric value, that
  2558.           value    will be    passed rather than a pointer to    the
  2559.           string value.     To guarantee this to be TRUE, add a 0
  2560.           to the scalar    before using it.)  The pack() and
  2561.           unpack() functions are useful    for manipulating the
  2562.           values of structures used by ioctl().     The following
  2563.           example sets the erase character to DEL.
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.      Page 39                        (printed 10/23/98)
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2579.  
  2580.  
  2581.  
  2582.               require 'ioctl.ph';
  2583.               $getp = &TIOCGETP;
  2584.               die "NO TIOCGETP"    if $@ || !$getp;
  2585.               $sgttyb_t    = "ccccs";          # 4 chars and    a short
  2586.               if (ioctl(STDIN,$getp,$sgttyb)) {
  2587.               @ary = unpack($sgttyb_t,$sgttyb);
  2588.               $ary[2] = 127;
  2589.               $sgttyb = pack($sgttyb_t,@ary);
  2590.               ioctl(STDIN,&TIOCSETP,$sgttyb)
  2591.                   || die "Can't ioctl: $!";
  2592.               }
  2593.  
  2594.           The return value of ioctl() (and fcntl()) is as
  2595.           follows:
  2596.  
  2597.               if OS    returns:      then Perl returns:
  2598.                   -1            undefined value
  2599.                    0          string "0 but    true"
  2600.               anything else              that number
  2601.  
  2602.           Thus Perl returns TRUE on success and    FALSE on
  2603.           failure, yet you can still easily determine the
  2604.           actual value returned    by the operating system:
  2605.  
  2606.               ($retval = ioctl(...)) ||    ($retval = -1);
  2607.               printf "System returned %d\n", $retval;
  2608.  
  2609.           The special string "0    but true" is excempt from ----wwww
  2610.           complaints about improper numeric conversions.
  2611.  
  2612.       join EXPR,LIST
  2613.           Joins    the separate strings of    LIST into a single
  2614.           string with fields separated by the value of EXPR,
  2615.           and returns the string.  Example:
  2616.  
  2617.               $_ = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
  2618.  
  2619.           See the split    entry elsewhere    in this    document.
  2620.  
  2621.       keys HASH
  2622.           Returns a list consisting of all the keys of the
  2623.           named    hash.  (In a scalar context, returns the
  2624.           number of keys.)  The    keys are returned in an
  2625.           apparently random order, but it is the same order as
  2626.           either the values() or each()    function produces
  2627.           (given that the hash has not been modified).    As a
  2628.           side effect, it resets HASH's    iterator.
  2629.  
  2630.           Here is yet another way to print your    environment:
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.      Page 40                        (printed 10/23/98)
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2645.  
  2646.  
  2647.  
  2648.               @keys = keys %ENV;
  2649.               @values =    values %ENV;
  2650.               while ($#keys >= 0) {
  2651.               print    pop(@keys), '=', pop(@values), "\n";
  2652.               }
  2653.  
  2654.           or how about sorted by key:
  2655.  
  2656.               foreach $key (sort(keys %ENV)) {
  2657.               print    $key, '=', $ENV{$key}, "\n";
  2658.               }
  2659.  
  2660.           To sort an array by value, you'll need to use    a
  2661.           sort() function.  Here's a descending    numeric    sort
  2662.           of a hash by its values:
  2663.  
  2664.               foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
  2665.               printf "%4d %s\n", $hash{$key}, $key;
  2666.               }
  2667.  
  2668.           As an    lvalue keys() allows you to increase the
  2669.           number of hash buckets allocated for the given hash.
  2670.           This can gain    you a measure of efficiency if you
  2671.           know the hash    is going to get    big.  (This is similar
  2672.           to pre-extending an array by assigning a larger
  2673.           number to $#array.)  If you say
  2674.  
  2675.               keys %hash = 200;
  2676.  
  2677.           then %hash will have at least    200 buckets allocated
  2678.           for it--256 of them, in fact,    since it rounds    up to
  2679.           the next power of two.  These    buckets    will be
  2680.           retained even    if you do %hash    = (), use undef    %hash
  2681.           if you want to free the storage while    %hash is still
  2682.           in scope.  You can't shrink the number of buckets
  2683.           allocated for    the hash using keys() in this way (but
  2684.           you needn't worry about doing    this by    accident, as
  2685.           trying has no    effect).
  2686.  
  2687.       kill LIST
  2688.           Sends    a signal to a list of processes.  The first
  2689.           element of the list must be the signal to send.
  2690.           Returns the number of    processes successfully
  2691.           signaled.
  2692.  
  2693.               $cnt = kill 1, $child1, $child2;
  2694.               kill 9, @goners;
  2695.  
  2696.           Unlike in the    shell, in Perl if the _S_I_G_N_A_L is
  2697.           negative, it kills process groups instead of
  2698.           processes.  (On System V, a negative _P_R_O_C_E_S_S number
  2699.           will also kill process groups, but that's not
  2700.  
  2701.  
  2702.  
  2703.      Page 41                        (printed 10/23/98)
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2711.  
  2712.  
  2713.  
  2714.           portable.)  That means you usually want to use
  2715.           positive not negative    signals.  You may also use a
  2716.           signal name in quotes.  See the section on _S_i_g_n_a_l_s
  2717.           in the _p_e_r_l_i_p_c manpage for details.
  2718.  
  2719.       last LABEL
  2720.  
  2721.       last      The last command is like the break statement in C
  2722.           (as used in loops); it immediately exits the loop in
  2723.           question.  If    the LABEL is omitted, the command
  2724.           refers to the    innermost enclosing loop.  The
  2725.           continue block, if any, is not executed:
  2726.  
  2727.               LINE: while (<STDIN>) {
  2728.               last LINE if /^$/;      # exit when done with    header
  2729.               #...
  2730.               }
  2731.  
  2732.           See also the continue    entry elsewhere    in this
  2733.           documentfor an illustration of how last, next, and
  2734.           redo work.
  2735.  
  2736.       lc EXPR
  2737.  
  2738.       lc      Returns an lowercased    version    of EXPR.  This is the
  2739.           internal function implementing the \L    escape in
  2740.           double-quoted    strings.  Respects current LC_CTYPE
  2741.           locale if use    locale in force.  See the _p_e_r_l_l_o_c_a_l_e
  2742.           manpage.
  2743.  
  2744.           If EXPR is omitted, uses $_.
  2745.  
  2746.       lcfirst EXPR
  2747.  
  2748.       lcfirst Returns the value of EXPR with the first character
  2749.           lowercased.  This is the internal function
  2750.           implementing the \l escape in    double-quoted strings.
  2751.           Respects current LC_CTYPE locale if use locale in
  2752.           force.  See the _p_e_r_l_l_o_c_a_l_e manpage.
  2753.  
  2754.           If EXPR is omitted, uses $_.
  2755.  
  2756.       length EXPR
  2757.  
  2758.       length  Returns the length in    bytes of the value of EXPR.
  2759.           If EXPR is omitted, returns length of    $_.
  2760.  
  2761.       link OLDFILE,NEWFILE
  2762.           Creates a new    filename linked    to the old filename.
  2763.           Returns TRUE for success, FALSE otherwise.
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.      Page 42                        (printed 10/23/98)
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2777.  
  2778.  
  2779.  
  2780.       listen SOCKET,QUEUESIZE
  2781.           Does the same    thing that the listen system call
  2782.           does.     Returns TRUE if it succeeded, FALSE
  2783.           otherwise.  See example in the section on _S_o_c_k_e_t_s:
  2784.           _C_l_i_e_n_t/_S_e_r_v_e_r    _C_o_m_m_u_n_i_c_a_t_i_o_n in the _p_e_r_l_i_p_c manpage.
  2785.  
  2786.       local    EXPR
  2787.           A local modifies the listed variables    to be local to
  2788.           the enclosing    block, file, or    eval.  If more than
  2789.           one value is listed, the list    must be    placed in
  2790.           parentheses.    See the    section    on _T_e_m_p_o_r_a_r_y _V_a_l_u_e_s
  2791.           _v_i_a _l_o_c_a_l() in the _p_e_r_l_s_u_b manpage for details,
  2792.           including issues with    tied arrays and    hashes.
  2793.  
  2794.           You really probably want to be using my() instead,
  2795.           because local() isn't    what most people think of as
  2796.           "local".  See    the section on _P_r_i_v_a_t_e _V_a_r_i_a_b_l_e_s _v_i_a
  2797.           _m_y() in the _p_e_r_l_s_u_b manpage for details.
  2798.  
  2799.       localtime EXPR
  2800.           Converts a time as returned by the time function to
  2801.           a 9-element array with the time analyzed for the
  2802.           local    time zone.  Typically used as follows:
  2803.  
  2804.               #     0    1       2     3     4    5      6    7     8
  2805.               ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  2806.                                   localtime(time);
  2807.  
  2808.           All array elements are numeric, and come straight
  2809.           out of a struct tm.  In particular this means    that
  2810.           $mon has the range 0..11 and $wday has the range
  2811.           0..6 with sunday as day 0.  Also, $year is the
  2812.           number of years since    1900, that is, $year is    123 in
  2813.           year 2023, and _n_o_t simply the    last two digits    of the
  2814.           year.
  2815.  
  2816.           If EXPR is omitted, uses the current time
  2817.           (localtime(time)).
  2818.  
  2819.           In scalar context, returns the _c_t_i_m_e(3) value:
  2820.  
  2821.               $now_string = localtime;    # e.g.,    "Thu Oct 13 04:54:34 1994"
  2822.  
  2823.           This scalar value is nnnnooootttt locale dependent, see the
  2824.           _p_e_r_l_l_o_c_a_l_e manpage, but instead a Perl builtin.
  2825.           Also see the Time::Local module, and the _s_t_r_f_t_i_m_e(3)
  2826.           and _m_k_t_i_m_e(3)    function available via the POSIX
  2827.           module.  To get somewhat similar but locale
  2828.           dependent date strings, set up your locale
  2829.           environment variables    appropriately (please see the
  2830.           _p_e_r_l_l_o_c_a_l_e manpage) and try for example:
  2831.  
  2832.  
  2833.  
  2834.  
  2835.      Page 43                        (printed 10/23/98)
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2843.  
  2844.  
  2845.  
  2846.               use POSIX    qw(strftime);
  2847.               $now_string =    strftime "%a %b    %e %H:%M:%S %Y", localtime;
  2848.  
  2849.           Note that the    %a and %b, the short forms of the day
  2850.           of the week and the month of the year, may not
  2851.           necessarily be three characters wide.
  2852.  
  2853.       log EXPR
  2854.  
  2855.       log      Returns the natural logarithm    (base _e) of EXPR.  If
  2856.           EXPR is omitted, returns log of $_.
  2857.  
  2858.       lstat    FILEHANDLE
  2859.  
  2860.       lstat    EXPR
  2861.  
  2862.       lstat      Does the same    thing as the stat() function
  2863.           (including setting the special _ filehandle) but
  2864.           stats    a symbolic link    instead    of the file the
  2865.           symbolic link    points to.  If symbolic    links are
  2866.           unimplemented    on your    system,    a normal stat()    is
  2867.           done.
  2868.  
  2869.           If EXPR is omitted, stats $_.
  2870.  
  2871.       m//      The match operator.  See the _p_e_r_l_o_p manpage.
  2872.  
  2873.       map BLOCK LIST
  2874.  
  2875.       map EXPR,LIST
  2876.           Evaluates the    BLOCK or EXPR for each element of LIST
  2877.           (locally setting $_ to each element) and returns the
  2878.           list value composed of the results of    each such
  2879.           evaluation.  Evaluates BLOCK or EXPR in a list
  2880.           context, so each element of LIST may produce zero,
  2881.           one, or more elements    in the returned    value.
  2882.  
  2883.               @chars = map(chr,    @nums);
  2884.  
  2885.           translates a list of numbers to the corresponding
  2886.           characters.  And
  2887.  
  2888.               %hash = map { getkey($_) => $_ } @array;
  2889.  
  2890.           is just a funny way to write
  2891.  
  2892.               %hash = ();
  2893.               foreach $_ (@array) {
  2894.               $hash{getkey($_)} = $_;
  2895.               }
  2896.  
  2897.           Note that, because $_    is a reference into the    list
  2898.  
  2899.  
  2900.  
  2901.      Page 44                        (printed 10/23/98)
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2909.  
  2910.  
  2911.  
  2912.           value, it can    be used    to modify the elements of the
  2913.           array.  While    this is    useful and supported, it can
  2914.           cause    bizarre    results    if the LIST is not a named
  2915.           array.  See also the grep entry elsewhere in this
  2916.           documentfor an array composed    of those items of the
  2917.           original list    for which the BLOCK or EXPR evaluates
  2918.           to true.
  2919.  
  2920.       mkdir    FILENAME,MODE
  2921.           Creates the directory    specified by FILENAME, with
  2922.           permissions specified    by MODE    (as modified by
  2923.           umask).  If it succeeds it returns TRUE, otherwise
  2924.           it returns FALSE and sets $! (errno).
  2925.  
  2926.       msgctl ID,CMD,ARG
  2927.           Calls    the System V IPC function _m_s_g_c_t_l(2).  You'll
  2928.           probably have    to say
  2929.  
  2930.               use IPC::SysV;
  2931.  
  2932.           first    to get the correct constant definitions.  If
  2933.           CMD is IPC_STAT, then    ARG must be a variable which
  2934.           will hold the    returned msqid_ds structure.  Returns
  2935.           like ioctl():    the undefined value for    error, "0 but
  2936.           true"    for zero, or the actual    return value
  2937.           otherwise.  See also IPC::SysV and
  2938.           IPC::Semaphore::Msg documentation.
  2939.  
  2940.       msgget KEY,FLAGS
  2941.           Calls    the System V IPC function _m_s_g_g_e_t(2).  Returns
  2942.           the message queue id,    or the undefined value if
  2943.           there    is an error.  See also IPC::SysV and
  2944.           IPC::SysV::Msg documentation.
  2945.  
  2946.       msgsnd ID,MSG,FLAGS
  2947.           Calls    the System V IPC function msgsnd to send the
  2948.           message MSG to the message queue ID.    MSG must begin
  2949.           with the long    integer    message    type, which may    be
  2950.           created with pack("l", $type).  Returns TRUE if
  2951.           successful, or FALSE if there    is an error.  See also
  2952.           IPC::SysV and    IPC::SysV::Msg documentation.
  2953.  
  2954.       msgrcv ID,VAR,SIZE,TYPE,FLAGS
  2955.           Calls    the System V IPC function msgrcv to receive a
  2956.           message from message queue ID    into variable VAR with
  2957.           a maximum message size of SIZE.  Note    that if    a
  2958.           message is received, the message type    will be    the
  2959.           first    thing in VAR, and the maximum length of    VAR is
  2960.           SIZE plus the    size of    the message type.  Returns
  2961.           TRUE if successful, or FALSE if there    is an error.
  2962.           See also IPC::SysV and IPC::SysV::Msg    documentation.
  2963.  
  2964.  
  2965.  
  2966.  
  2967.      Page 45                        (printed 10/23/98)
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2975.  
  2976.  
  2977.  
  2978.       my EXPR A my() declares the listed variables to be local
  2979.           (lexically) to the enclosing block, file, or eval().
  2980.           If more than one value is listed, the    list must be
  2981.           placed in parentheses.  See the section on _P_r_i_v_a_t_e
  2982.           _V_a_r_i_a_b_l_e_s _v_i_a    _m_y() in    the _p_e_r_l_s_u_b manpage for
  2983.           details.
  2984.  
  2985.       next LABEL
  2986.  
  2987.       next      The next command is like the continue    statement in
  2988.           C; it    starts the next    iteration of the loop:
  2989.  
  2990.               LINE: while (<STDIN>) {
  2991.               next LINE if /^#/;      # discard comments
  2992.               #...
  2993.               }
  2994.  
  2995.           Note that if there were a continue block on the
  2996.           above, it would get executed even on discarded
  2997.           lines.  If the LABEL is omitted, the command refers
  2998.           to the innermost enclosing loop.
  2999.  
  3000.           See also the continue    entry elsewhere    in this
  3001.           documentfor an illustration of how last, next, and
  3002.           redo work.
  3003.  
  3004.       no Module LIST
  3005.           See the the use entry    elsewhere in this
  3006.           documentfunction, which no is    the opposite of.
  3007.  
  3008.       oct EXPR
  3009.  
  3010.       oct      Interprets EXPR as an    octal string and returns the
  3011.           corresponding    value.    (If EXPR happens to start off
  3012.           with 0x, interprets it as a hex string instead.)
  3013.           The following    will handle decimal, octal, and    hex in
  3014.           the standard Perl or C notation:
  3015.  
  3016.               $val = oct($val) if $val =~ /^0/;
  3017.  
  3018.           If EXPR is omitted, uses $_.    This function is
  3019.           commonly used    when a string such as 644 needs    to be
  3020.           converted into a file    mode, for example. (Although
  3021.           perl will automatically convert strings into numbers
  3022.           as needed, this automatic conversion assumes base
  3023.           10.)
  3024.  
  3025.       open FILEHANDLE,EXPR
  3026.  
  3027.       open FILEHANDLE
  3028.           Opens    the file whose filename    is given by EXPR, and
  3029.           associates it    with FILEHANDLE.  If FILEHANDLE    is an
  3030.  
  3031.  
  3032.  
  3033.      Page 46                        (printed 10/23/98)
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3041.  
  3042.  
  3043.  
  3044.           expression, its value    is used    as the name of the
  3045.           real filehandle wanted.  If EXPR is omitted, the
  3046.           scalar variable of the same name as the FILEHANDLE
  3047.           contains the filename.  (Note    that lexical
  3048.           variables--those declared with my()--will not    work
  3049.           for this purpose; so if you're using my(), specify
  3050.           EXPR in your call to open.)
  3051.  
  3052.           If the filename begins with '<' or nothing, the file
  3053.           is opened for    input.    If the filename    begins with
  3054.           '>', the file    is truncated and opened    for output,
  3055.           being    created    if necessary. If the filename begins
  3056.           with '>>', the file is opened    for appending, again
  3057.           being    created    if necessary. You can put a '+'    in
  3058.           front    of the '>' or '<' to indicate that you want
  3059.           both read and    write access to    the file; thus '+<' is
  3060.           almost always    preferred for read/write updates--the
  3061.           '+>' mode would clobber the file first.  You can't
  3062.           usually use either read-write    mode for updating
  3063.           textfiles, since they    have variable length records.
  3064.           See the ----iiii switch in the _p_e_r_l_r_u_n manpage for a
  3065.           better approach.
  3066.  
  3067.           The prefix and the filename may be separated with
  3068.           spaces.  These various prefixes correspond to    the
  3069.           _f_o_p_e_n(3) modes of 'r', 'r+', 'w', 'w+', 'a', and
  3070.           'a+'.
  3071.  
  3072.           If the filename begins with '|', the filename    is
  3073.           interpreted as a command to which output is to be
  3074.           piped, and if    the filename ends with a '|', the
  3075.           filename is interpreted See the section on _U_s_i_n_g
  3076.           _o_p_e_n() _f_o_r _I_P_C in the    _p_e_r_l_i_p_c    manpage    for more
  3077.           examples of this.  (You are not allowed to open() to
  3078.           a command that pipes both in _a_n_d out,    but see    the
  3079.           _I_P_C::_O_p_e_n_2 manpage, the _I_P_C::_O_p_e_n_3 manpage, and the
  3080.           section on _B_i_d_i_r_e_c_t_i_o_n_a_l _C_o_m_m_u_n_i_c_a_t_i_o_n in the
  3081.           _p_e_r_l_i_p_c manpage for alternatives.)
  3082.  
  3083.           Opening '-' opens STDIN and opening '>-' opens
  3084.           STDOUT.  Open    returns    nonzero    upon success, the
  3085.           undefined value otherwise.  If the open() involved a
  3086.           pipe,    the return value happens to be the pid of the
  3087.           subprocess.
  3088.  
  3089.           If you're unfortunate    enough to be running Perl on a
  3090.           system that distinguishes between text files and
  3091.           binary files (modern operating systems don't care),
  3092.           then you should check    out the    binmode    entry
  3093.           elsewhere in this documentfor    tips for dealing with
  3094.           this.     The key distinction between systems that need
  3095.           binmode() and    those that don't is their text file
  3096.  
  3097.  
  3098.  
  3099.      Page 47                        (printed 10/23/98)
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3107.  
  3108.  
  3109.  
  3110.           formats.  Systems like Unix, MacOS, and Plan9, which
  3111.           delimit lines    with a single character, and which
  3112.           encode that character    in C as    "\n", do not need
  3113.           binmode().  The rest need it.
  3114.  
  3115.           When opening a file, it's usually a bad idea to
  3116.           continue normal execution if the request failed, so
  3117.           open() is frequently used in connection with die().
  3118.           Even if die()    won't do what you want (say, in    a CGI
  3119.           script, where    you want to make a nicely formatted
  3120.           error    message    (but there are modules that can    help
  3121.           with that problem)) you should always    check the
  3122.           return value from opening a file. The    infrequent
  3123.           exception is when working with an unopened
  3124.           filehandle is    actually what you want to do.
  3125.  
  3126.           Examples:
  3127.  
  3128.               $ARTICLE = 100;
  3129.               open ARTICLE or die "Can't find article $ARTICLE:    $!\n";
  3130.               while (<ARTICLE>)    {...
  3131.  
  3132.               open(LOG,    '>>/usr/spool/news/twitlog'); #    (log is    reserved)
  3133.               #    if the open fails, output is discarded
  3134.  
  3135.               open(DBASE, '+<dbase.mine')          #    open for update
  3136.               or die "Can't    open 'dbase.mine' for update: $!";
  3137.  
  3138.               open(ARTICLE, "caesar <$article |")     #    decrypt    article
  3139.               or die "Can't    start caesar: $!";
  3140.  
  3141.               open(EXTRACT, "|sort >/tmp/Tmp$$")      #    $$ is our process id
  3142.               or die "Can't    start sort: $!";
  3143.  
  3144.               #    process    argument list of files along with any includes
  3145.  
  3146.               foreach $file (@ARGV) {
  3147.               process($file, 'fh00');
  3148.               }
  3149.  
  3150.               sub process {
  3151.               my($filename,    $input)    = @_;
  3152.               $input++;          # this is a string increment
  3153.               unless (open($input, $filename)) {
  3154.                   print STDERR "Can't open $filename: $!\n";
  3155.                   return;
  3156.               }
  3157.  
  3158.  
  3159.  
  3160.  
  3161.  
  3162.  
  3163.  
  3164.  
  3165.      Page 48                        (printed 10/23/98)
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3173.  
  3174.  
  3175.  
  3176.               local    $_;
  3177.               while    (<$input>) {          # note use of    indirection
  3178.                   if (/^#include "(.*)"/) {
  3179.                   process($1, $input);
  3180.                   next;
  3181.                   }
  3182.                   #...          # whatever
  3183.               }
  3184.               }
  3185.  
  3186.           You may also,    in the Bourne shell tradition, specify
  3187.           an EXPR beginning with '>&', in which    case the rest
  3188.           of the string    is interpreted as the name of a
  3189.           filehandle (or file descriptor, if numeric) to be
  3190.           duped    and opened.  You may use & after >, >>,    <, +>,
  3191.           +>>, and +<.    The mode you specify should match the
  3192.           mode of the original filehandle.  (Duping a
  3193.           filehandle does not take into    account    any existing
  3194.           contents of stdio buffers.)  Here is a script    that
  3195.           saves, redirects, and    restores STDOUT    and STDERR:
  3196.  
  3197.               #!/usr/bin/perl
  3198.               open(OLDOUT, ">&STDOUT");
  3199.               open(OLDERR, ">&STDERR");
  3200.  
  3201.               open(STDOUT, ">foo.out") || die "Can't redirect stdout";
  3202.               open(STDERR, ">&STDOUT") || die "Can't dup stdout";
  3203.  
  3204.               select(STDERR); $| = 1;      # make unbuffered
  3205.               select(STDOUT); $| = 1;      # make unbuffered
  3206.  
  3207.               print STDOUT "stdout 1\n";  # this works for
  3208.               print STDERR "stderr 1\n";  # subprocesses too
  3209.  
  3210.               close(STDOUT);
  3211.               close(STDERR);
  3212.  
  3213.               open(STDOUT, ">&OLDOUT");
  3214.               open(STDERR, ">&OLDERR");
  3215.  
  3216.               print STDOUT "stdout 2\n";
  3217.               print STDERR "stderr 2\n";
  3218.  
  3219.           If you specify '<&=N', where N is a number, then
  3220.           Perl will do an equivalent of    C's fdopen() of    that
  3221.           file descriptor; this    is more    parsimonious of    file
  3222.           descriptors.    For example:
  3223.  
  3224.               open(FILEHANDLE, "<&=$fd")
  3225.  
  3226.           If you open a    pipe on    the command '-', i.e., either
  3227.           '|-' or '-|',    then there is an implicit fork done,
  3228.  
  3229.  
  3230.  
  3231.      Page 49                        (printed 10/23/98)
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3239.  
  3240.  
  3241.  
  3242.           and the return value of open is the pid of the child
  3243.           within the parent process, and 0 within the child
  3244.           process.  (Use defined($pid) to determine whether
  3245.           the open was successful.)  The filehandle behaves
  3246.           normally for the parent, but i/o to that filehandle
  3247.           is piped from/to the STDOUT/STDIN of the child
  3248.           process.  In the child process the filehandle    isn't
  3249.           opened--i/o happens from/to the new STDOUT or    STDIN.
  3250.           Typically this is used like the normal piped open
  3251.           when you want    to exercise more control over just how
  3252.           the pipe command gets    executed, such as when you are
  3253.           running setuid, and don't want to have to scan shell
  3254.           commands for metacharacters.    The following pairs
  3255.           are more or less equivalent:
  3256.  
  3257.               open(FOO,    "|tr '[a-z]' '[A-Z]'");
  3258.               open(FOO,    "|-") || exec 'tr', '[a-z]', '[A-Z]';
  3259.  
  3260.               open(FOO,    "cat -n    '$file'|");
  3261.               open(FOO,    "-|") || exec 'cat', '-n', $file;
  3262.  
  3263.           See the section on _S_a_f_e _P_i_p_e _O_p_e_n_s in    the _p_e_r_l_i_p_c
  3264.           manpage for more examples of this.
  3265.  
  3266.           NOTE:    On any operation that may do a fork, any
  3267.           unflushed buffers remain unflushed in    both
  3268.           processes, which means you may need to set $|    to
  3269.           avoid    duplicate output.
  3270.  
  3271.           Closing any piped filehandle causes the parent
  3272.           process to wait for the child    to finish, and returns
  3273.           the status value in $?.
  3274.  
  3275.           The filename passed to open will have    leading    and
  3276.           trailing whitespace deleted, and the normal
  3277.           redirection characters honored.  This    property,
  3278.           known    as "magic open", can often be used to good
  3279.           effect.  A user could    specify    a filename of "_r_s_h _c_a_t
  3280.           _f_i_l_e |", or you could    change certain filenames as
  3281.           needed:
  3282.  
  3283.               $filename    =~ s/(.*\.gz)\s*$/gzip -dc < $1|/;
  3284.               open(FH, $filename) or die "Can't    open $filename:    $!";
  3285.  
  3286.           However, to open a file with arbitrary weird
  3287.           characters in    it, it's necessary to protect any
  3288.           leading and trailing whitespace:
  3289.  
  3290.               $file =~ s#^(\s)#./$1#;
  3291.               open(FOO,    "< $file\0");
  3292.  
  3293.           If you want a    "real" C open()    (see the _o_p_e_n(_2)
  3294.  
  3295.  
  3296.  
  3297.      Page 50                        (printed 10/23/98)
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3305.  
  3306.  
  3307.  
  3308.           manpage on your system), then    you should use the
  3309.           sysopen() function, which involves no    such magic.
  3310.           This is another way to protect your filenames    from
  3311.           interpretation.  For example:
  3312.  
  3313.               use IO::Handle;
  3314.               sysopen(HANDLE, $path, O_RDWR|O_CREAT|O_EXCL)
  3315.               or die "sysopen $path: $!";
  3316.               $oldfh = select(HANDLE); $| = 1; select($oldfh);
  3317.               print HANDLE "stuff $$\n");
  3318.               seek(HANDLE, 0, 0);
  3319.               print "File contains: ", <HANDLE>;
  3320.  
  3321.           Using    the constructor    from the IO::Handle package
  3322.           (or one of its subclasses, such as IO::File or
  3323.           IO::Socket), you can generate    anonymous filehandles
  3324.           that have the    scope of whatever variables hold
  3325.           references to    them, and automatically    close whenever
  3326.           and however you leave    that scope:
  3327.  
  3328.               use IO::File;
  3329.               #...
  3330.               sub read_myfile_munged {
  3331.               my $ALL = shift;
  3332.               my $handle = new IO::File;
  3333.               open($handle,    "myfile") or die "myfile: $!";
  3334.               $first = <$handle>
  3335.                   or return    ();    # Automatically    closed here.
  3336.               mung $first or die "mung failed";      # Or here.
  3337.               return $first, <$handle> if $ALL;      # Or here.
  3338.               $first;                  # Or here.
  3339.               }
  3340.  
  3341.           See the seek() entry elsewhere in this documentfor
  3342.           some details about mixing reading and    writing.
  3343.  
  3344.       opendir DIRHANDLE,EXPR
  3345.           Opens    a directory named EXPR for processing by
  3346.           readdir(), telldir(),    seekdir(), rewinddir(),    and
  3347.           closedir().  Returns TRUE if successful.  DIRHANDLEs
  3348.           have their own namespace separate from FILEHANDLEs.
  3349.  
  3350.       ord EXPR
  3351.  
  3352.       ord      Returns the numeric ascii value of the first
  3353.           character of EXPR.  If EXPR is omitted, uses $_.
  3354.           For the reverse, see the chr entry elsewhere in this
  3355.           document.
  3356.  
  3357.       pack TEMPLATE,LIST
  3358.           Takes    an array or list of values and packs it    into a
  3359.           binary structure, returning the string containing
  3360.  
  3361.  
  3362.  
  3363.      Page 51                        (printed 10/23/98)
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3371.  
  3372.  
  3373.  
  3374.           the structure.  The TEMPLATE is a sequence of
  3375.           characters that give the order and type of values,
  3376.           as follows:
  3377.  
  3378.               A      An ascii string, will    be space padded.
  3379.               a      An ascii string, will    be null    padded.
  3380.               b      A bit    string (ascending bit order, like vec()).
  3381.               B      A bit    string (descending bit order).
  3382.               h      A hex    string (low nybble first).
  3383.               H      A hex    string (high nybble first).
  3384.  
  3385.               c      A signed char    value.
  3386.               C      An unsigned char value.
  3387.  
  3388.               s      A signed short value.
  3389.               S      An unsigned short value.
  3390.                 (This 'short' is _exactly_ 16 bits,    which may differ from
  3391.                  what a local C compiler calls 'short'.)
  3392.  
  3393.               i      A signed integer value.
  3394.               I      An unsigned integer value.
  3395.                 (This 'integer' is _at_least_ 32 bits wide.     Its exact
  3396.                  size depends on what a local C compiler calls 'int',
  3397.                  and may even be larger than the 'long' described in
  3398.                  the next item.)
  3399.  
  3400.               l      A signed long    value.
  3401.               L      An unsigned long value.
  3402.                 (This 'long' is _exactly_ 32 bits, which may differ    from
  3403.                  what a local C compiler calls 'long'.)
  3404.  
  3405.               n      A short in "network" (big-endian) order.
  3406.               N      A long in "network" (big-endian) order.
  3407.               v      A short in "VAX" (little-endian) order.
  3408.               V      A long in "VAX" (little-endian) order.
  3409.                 (These 'shorts' and    'longs'    are _exactly_ 16 bits and
  3410.                  _exactly_ 32 bits,    respectively.)
  3411.  
  3412.               f      A single-precision float in the native format.
  3413.               d      A double-precision float in the native format.
  3414.  
  3415.               p      A pointer to a null-terminated string.
  3416.               P      A pointer to a structure (fixed-length string).
  3417.  
  3418.               u      A uuencoded string.
  3419.  
  3420.               w      A BER    compressed integer.  Its bytes represent an unsigned
  3421.               integer in base 128, most significant    digit first, with as
  3422.               few digits as    possible.  Bit eight (the high bit) is set
  3423.               on each byte except the last.
  3424.  
  3425.  
  3426.  
  3427.  
  3428.  
  3429.      Page 52                        (printed 10/23/98)
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3437.  
  3438.  
  3439.  
  3440.               x      A null byte.
  3441.               X      Back up a byte.
  3442.               @      Null fill to absolute    position.
  3443.  
  3444.           Each letter may optionally be    followed by a number
  3445.           giving a repeat count.  With all types except    "a",
  3446.           "A", "b", "B", "h", "H", and "P" the pack function
  3447.           will gobble up that many values from the LIST.  A *
  3448.           for the repeat count means to    use however many items
  3449.           are left.  The "a" and "A" types gobble just one
  3450.           value, but pack it as    a string of length count,
  3451.           padding with nulls or    spaces as necessary.  (When
  3452.           unpacking, "A" strips    trailing spaces    and nulls, but
  3453.           "a" does not.)  Likewise, the    "b" and    "B" fields
  3454.           pack a string    that many bits long.  The "h" and "H"
  3455.           fields pack a    string that many nybbles long.    The
  3456.           "p" type packs a pointer to a    null- terminated
  3457.           string.  You are responsible for ensuring the    string
  3458.           is not a temporary value (which can potentially get
  3459.           deallocated before you get around to using the
  3460.           packed result).  The "P" packs a pointer to a
  3461.           structure of the size    indicated by the length. A
  3462.           NULL pointer is created if the corresponding value
  3463.           for "p" or "P" is undef.  Real numbers (floats and
  3464.           doubles) are in the native machine format only; due
  3465.           to the multiplicity of floating formats around, and
  3466.           the lack of a    standard "network" representation, no
  3467.           facility for interchange has been made.  This    means
  3468.           that packed floating point data written on one
  3469.           machine may not be readable on another - even    if
  3470.           both use IEEE    floating point arithmetic (as the
  3471.           endian-ness of the memory representation is not part
  3472.           of the IEEE spec).  Note that    Perl uses doubles
  3473.           internally for all numeric calculation, and
  3474.           converting from double into float and    thence back to
  3475.           double again will lose precision (i.e., unpack("f",
  3476.           pack("f", $foo)) will    not in general equal $foo).
  3477.  
  3478.           Examples:
  3479.  
  3480.               $foo = pack("cccc",65,66,67,68);
  3481.               #    foo eq "ABCD"
  3482.               $foo = pack("c4",65,66,67,68);
  3483.               #    same thing
  3484.  
  3485.               $foo = pack("ccxxcc",65,66,67,68);
  3486.               #    foo eq "AB\0\0CD"
  3487.  
  3488.               $foo = pack("s2",1,2);
  3489.               #    "\1\0\2\0" on little-endian
  3490.               #    "\0\1\0\2" on big-endian
  3491.  
  3492.  
  3493.  
  3494.  
  3495.      Page 53                        (printed 10/23/98)
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3503.  
  3504.  
  3505.  
  3506.               $foo = pack("a4","abcd","x","y","z");
  3507.               #    "abcd"
  3508.  
  3509.               $foo = pack("aaaa","abcd","x","y","z");
  3510.               #    "axyz"
  3511.  
  3512.               $foo = pack("a14","abcdefg");
  3513.               #    "abcdefg\0\0\0\0\0\0\0"
  3514.  
  3515.               $foo = pack("i9pl", gmtime);
  3516.               #    a real struct tm (on my    system anyway)
  3517.  
  3518.               sub bintodec {
  3519.               unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
  3520.               }
  3521.  
  3522.           The same template may    generally also be used in the
  3523.           unpack function.
  3524.  
  3525.       package
  3526.  
  3527.       package NAMESPACE
  3528.           Declares the compilation unit    as being in the    given
  3529.           namespace.  The scope    of the package declaration is
  3530.           from the declaration itself through the end of the
  3531.           enclosing block (the same scope as the local()
  3532.           operator).  All further unqualified dynamic
  3533.           identifiers will be in this namespace.  A package
  3534.           statement affects only dynamic variables--including
  3535.           those    you've used local() on--but _n_o_t    lexical
  3536.           variables created with my().    Typically it would be
  3537.           the first declaration    in a file to be    included by
  3538.           the require or use operator.    You can    switch into a
  3539.           package in more than one place; it merely influences
  3540.           which    symbol table is    used by    the compiler for the
  3541.           rest of that block.  You can refer to    variables and
  3542.           filehandles in other packages    by prefixing the
  3543.           identifier with the package name and a double    colon:
  3544.           $Package::Variable.  If the package name is null,
  3545.           the main package as assumed.    That is, $::sail is
  3546.           equivalent to    $main::sail.
  3547.  
  3548.           If NAMESPACE is omitted, then    there is no current
  3549.           package, and all identifiers must be fully qualified
  3550.           or lexicals.    This is    stricter than use strict,
  3551.           since    it also    extends    to function names.
  3552.  
  3553.           See the section on _P_a_c_k_a_g_e_s in the _p_e_r_l_m_o_d manpage
  3554.           for more information about packages, modules,    and
  3555.           classes.  See    the _p_e_r_l_s_u_b manpage for    other scoping
  3556.           issues.
  3557.  
  3558.  
  3559.  
  3560.  
  3561.      Page 54                        (printed 10/23/98)
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3569.  
  3570.  
  3571.  
  3572.       pipe READHANDLE,WRITEHANDLE
  3573.           Opens    a pair of connected pipes like the
  3574.           corresponding    system call.  Note that    if you set up
  3575.           a loop of piped processes, deadlock can occur    unless
  3576.           you are very careful.     In addition, note that    Perl's
  3577.           pipes    use stdio buffering, so    you may    need to    set $|
  3578.           to flush your    WRITEHANDLE after each command,
  3579.           depending on the application.
  3580.  
  3581.           See the _I_P_C::_O_p_e_n_2 manpage, the _I_P_C::_O_p_e_n_3 manpage,
  3582.           and the section on _B_i_d_i_r_e_c_t_i_o_n_a_l _C_o_m_m_u_n_i_c_a_t_i_o_n in
  3583.           the _p_e_r_l_i_p_c manpage for examples of such things.
  3584.  
  3585.       pop ARRAY
  3586.  
  3587.       pop      Pops and returns the last value of the array,
  3588.           shortening the array by 1.  Has a similar effect to
  3589.  
  3590.               $tmp = $ARRAY[$#ARRAY--];
  3591.  
  3592.           If there are no elements in the array, returns the
  3593.           undefined value.  If ARRAY is    omitted, pops the
  3594.           @ARGV    array in the main program, and the @_ array in
  3595.           subroutines, just like shift().
  3596.  
  3597.       pos SCALAR
  3598.  
  3599.       pos      Returns the offset of    where the last m//g search
  3600.           left off for the variable is in question ($_ is used
  3601.           when the variable is not specified).    May be
  3602.           modified to change that offset.  Such    modification
  3603.           will also influence the \G zero-width    assertion in
  3604.           regular expressions.    See the    _p_e_r_l_r_e manpage and the
  3605.           _p_e_r_l_o_p manpage.
  3606.  
  3607.       print    FILEHANDLE LIST
  3608.  
  3609.       print    LIST
  3610.  
  3611.       print      Prints a string or a comma-separated list of
  3612.           strings.  Returns TRUE if successful.     FILEHANDLE
  3613.           may be a scalar variable name, in which case the
  3614.           variable contains the    name of    or a reference to the
  3615.           filehandle, thus introducing one level of
  3616.           indirection.    (NOTE: If FILEHANDLE is    a variable and
  3617.           the next token is a term, it may be misinterpreted
  3618.           as an    operator unless    you interpose a    + or put
  3619.           parentheses around the arguments.)  If FILEHANDLE is
  3620.           omitted, prints by default to    standard output    (or to
  3621.           the last selected output channel--see    the select
  3622.           entry    elsewhere in this document).  If LIST is also
  3623.           omitted, prints $_ to    the currently selected output
  3624.  
  3625.  
  3626.  
  3627.      Page 55                        (printed 10/23/98)
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3635.  
  3636.  
  3637.  
  3638.           channel.  To set the default output channel to
  3639.           something other than STDOUT use the select
  3640.           operation.  Note that, because print takes a LIST,
  3641.           anything in the LIST is evaluated in list context,
  3642.           and any subroutine that you call will    have one or
  3643.           more of its expressions evaluated in list context.
  3644.           Also be careful not to follow    the print keyword with
  3645.           a left parenthesis unless you    want the corresponding
  3646.           right    parenthesis to terminate the arguments to the
  3647.           print--interpose a + or put parentheses around all
  3648.           the arguments.
  3649.  
  3650.           Note that if you're storing FILEHANDLES in an    array
  3651.           or other expression, you will    have to    use a block
  3652.           returning its    value instead:
  3653.  
  3654.               print { $files[$i] } "stuff\n";
  3655.               print { $OK ? STDOUT : STDERR } "stuff\n";
  3656.  
  3657.  
  3658.       printf FILEHANDLE FORMAT, LIST
  3659.  
  3660.       printf FORMAT, LIST
  3661.           Equivalent to    print FILEHANDLE sprintf(FORMAT,
  3662.           LIST), except    that $\    (the output record separator)
  3663.           is not appended.  The    first argument of the list
  3664.           will be interpreted as the printf() format.  If use
  3665.           locale is in effect, the character used for the
  3666.           decimal point    in formatted real numbers is affected
  3667.           by the LC_NUMERIC locale.  See the _p_e_r_l_l_o_c_a_l_e
  3668.           manpage.
  3669.  
  3670.           Don't    fall into the trap of using a printf() when a
  3671.           simple print() would do.  The    print()    is more
  3672.           efficient and    less error prone.
  3673.  
  3674.       prototype FUNCTION
  3675.           Returns the prototype    of a function as a string (or
  3676.           undef    if the function    has no prototype).  FUNCTION
  3677.           is a reference to, or    the name of, the function
  3678.           whose    prototype you want to retrieve.
  3679.  
  3680.           If FUNCTION is a string starting with    CORE::,    the
  3681.           rest is taken    as a name for Perl builtin.  If
  3682.           builtin is not _o_v_e_r_r_i_d_a_b_l_e (such as qw//) or its
  3683.           arguments cannot be expressed    by a prototype (such
  3684.           as system()) - in other words, the builtin does not
  3685.           behave like a    Perl function -    returns    undef.
  3686.           Otherwise, the string    describing the equivalent
  3687.           prototype is returned.
  3688.  
  3689.  
  3690.  
  3691.  
  3692.  
  3693.      Page 56                        (printed 10/23/98)
  3694.  
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3701.  
  3702.  
  3703.  
  3704.       push ARRAY,LIST
  3705.           Treats ARRAY as a stack, and pushes the values of
  3706.           LIST onto the    end of ARRAY.  The length of ARRAY
  3707.           increases by the length of LIST.  Has    the same
  3708.           effect as
  3709.  
  3710.               for $value (LIST)    {
  3711.               $ARRAY[++$#ARRAY] = $value;
  3712.               }
  3713.  
  3714.           but is more efficient.  Returns the new number of
  3715.           elements in the array.
  3716.  
  3717.       q/STRING/
  3718.  
  3719.       qq/STRING/
  3720.  
  3721.       qr/STRING/
  3722.  
  3723.       qx/STRING/
  3724.  
  3725.       qw/STRING/
  3726.           Generalized quotes.  See the _p_e_r_l_o_p manpage.
  3727.  
  3728.       quotemeta EXPR
  3729.  
  3730.       quotemeta
  3731.           Returns the value of EXPR with all non-alphanumeric
  3732.           characters backslashed.  (That is, all characters
  3733.           not matching /[A-Za-z_0-9]/ will be preceded by a
  3734.           backslash in the returned string, regardless of any
  3735.           locale settings.)  This is the internal function
  3736.           implementing the \Q escape in    double-quoted strings.
  3737.  
  3738.           If EXPR is omitted, uses $_.
  3739.  
  3740.       rand EXPR
  3741.  
  3742.       rand      Returns a random fractional number greater than or
  3743.           equal    to 0 and less than the value of    EXPR.  (EXPR
  3744.           should be positive.)    If EXPR    is omitted, the    value
  3745.           1 is used.  Automatically calls srand() unless
  3746.           srand() has already been called.  See    also srand().
  3747.  
  3748.           (Note: If your rand function consistently returns
  3749.           numbers that are too large or    too small, then    your
  3750.           version of Perl was probably compiled    with the wrong
  3751.           number of RANDBITS.)
  3752.  
  3753.       read FILEHANDLE,SCALAR,LENGTH,OFFSET
  3754.  
  3755.  
  3756.  
  3757.  
  3758.  
  3759.      Page 57                        (printed 10/23/98)
  3760.  
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3767.  
  3768.  
  3769.  
  3770.       read FILEHANDLE,SCALAR,LENGTH
  3771.           Attempts to read LENGTH bytes    of data    into variable
  3772.           SCALAR from the specified FILEHANDLE.     Returns the
  3773.           number of bytes actually read, 0 at end of file, or
  3774.           undef    if there was an    error.    SCALAR will be grown
  3775.           or shrunk to the length actually read.  An OFFSET
  3776.           may be specified to place the    read data at some
  3777.           other    place than the beginning of the    string.     This
  3778.           call is actually implemented in terms    of stdio's
  3779.           _f_r_e_a_d(3) call.  To get a true    _r_e_a_d(2)    system call,
  3780.           see sysread().
  3781.  
  3782.       readdir DIRHANDLE
  3783.           Returns the next directory entry for a directory
  3784.           opened by opendir().    If used    in list    context,
  3785.           returns all the rest of the entries in the
  3786.           directory.  If there are no more entries, returns an
  3787.           undefined value in scalar context or a null list in
  3788.           list context.
  3789.  
  3790.           If you're planning to    filetest the return values out
  3791.           of a readdir(), you'd    better prepend the directory
  3792.           in question.    Otherwise, because we didn't chdir()
  3793.           there, it would have been testing the    wrong file.
  3794.  
  3795.               opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
  3796.               @dots = grep { /^\./ && -f "$some_dir/$_"    } readdir(DIR);
  3797.               closedir DIR;
  3798.  
  3799.  
  3800.       readline EXPR
  3801.           Reads    from the filehandle whose typeglob is
  3802.           contained in EXPR.  In scalar    context, a single line
  3803.           is read and returned.     In list context, reads    until
  3804.           end-of-file is reached and returns a list of lines
  3805.           (however you've defined lines    with $/    or
  3806.           $INPUT_RECORD_SEPARATOR).  This is the internal
  3807.           function implementing    the <EXPR> operator, but you
  3808.           can use it directly.    The <EXPR> operator is
  3809.           discussed in more detail in the section on _I/_O
  3810.           _O_p_e_r_a_t_o_r_s in the _p_e_r_l_o_p manpage.
  3811.  
  3812.               $line = <STDIN>;
  3813.               $line = readline(*STDIN);          # same thing
  3814.  
  3815.  
  3816.       readlink EXPR
  3817.  
  3818.       readlink
  3819.           Returns the value of a symbolic link,    if symbolic
  3820.           links    are implemented.  If not, gives    a fatal    error.
  3821.           If there is some system error, returns the undefined
  3822.  
  3823.  
  3824.  
  3825.      Page 58                        (printed 10/23/98)
  3826.  
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3833.  
  3834.  
  3835.  
  3836.           value    and sets $! (errno).  If EXPR is omitted, uses
  3837.           $_.
  3838.  
  3839.       readpipe EXPR
  3840.           EXPR is executed as a    system command.     The collected
  3841.           standard output of the command is returned.  In
  3842.           scalar context, it comes back    as a single
  3843.           (potentially multi-line) string.  In list context,
  3844.           returns a list of lines (however you've defined
  3845.           lines    with $/    or $INPUT_RECORD_SEPARATOR).  This is
  3846.           the internal function    implementing the qx/EXPR/
  3847.           operator, but    you can    use it directly.  The qx/EXPR/
  3848.           operator is discussed    in more    detail in the section
  3849.           on _I/_O _O_p_e_r_a_t_o_r_s in the _p_e_r_l_o_p manpage.
  3850.  
  3851.       recv SOCKET,SCALAR,LEN,FLAGS
  3852.           Receives a message on    a socket.  Attempts to receive
  3853.           LENGTH bytes of data into variable SCALAR from the
  3854.           specified SOCKET filehandle.    Actually does a    C
  3855.           recvfrom(), so that it can return the    address    of the
  3856.           sender.  Returns the undefined value if there's an
  3857.           error.  SCALAR will be grown or shrunk to the    length
  3858.           actually read.  Takes    the same flags as the system
  3859.           call of the same name.  See the section on _U_D_P:
  3860.           _M_e_s_s_a_g_e _P_a_s_s_i_n_g in the _p_e_r_l_i_p_c manpage for examples.
  3861.  
  3862.       redo LABEL
  3863.  
  3864.       redo      The redo command restarts the    loop block without
  3865.           evaluating the conditional again.  The continue
  3866.           block, if any, is not    executed.  If the LABEL    is
  3867.           omitted, the command refers to the innermost
  3868.           enclosing loop.  This    command    is normally used by
  3869.           programs that    want to    lie to themselves about    what
  3870.           was just input:
  3871.  
  3872.               #    a simpleminded Pascal comment stripper
  3873.               #    (warning: assumes no { or } in strings)
  3874.               LINE: while (<STDIN>) {
  3875.               while    (s|({.*}.*){.*}|$1 |) {}
  3876.               s|{.*}| |;
  3877.               if (s|{.*| |)    {
  3878.                   $front = $_;
  3879.                   while (<STDIN>) {
  3880.                   if (/}/) {      # end    of comment?
  3881.                       s|^|$front\{|;
  3882.                       redo LINE;
  3883.                   }
  3884.                   }
  3885.               }
  3886.               print;
  3887.               }
  3888.  
  3889.  
  3890.  
  3891.      Page 59                        (printed 10/23/98)
  3892.  
  3893.  
  3894.  
  3895.  
  3896.  
  3897.  
  3898.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3899.  
  3900.  
  3901.  
  3902.           See also the continue    entry elsewhere    in this
  3903.           documentfor an illustration of how last, next, and
  3904.           redo work.
  3905.  
  3906.       ref EXPR
  3907.  
  3908.       ref      Returns a TRUE value if EXPR is a reference, FALSE
  3909.           otherwise.  If EXPR is not specified,    $_ will    be
  3910.           used.     The value returned depends on the type    of
  3911.           thing    the reference is a reference to.  Builtin
  3912.           types    include:
  3913.  
  3914.               REF
  3915.               SCALAR
  3916.               ARRAY
  3917.               HASH
  3918.               CODE
  3919.               GLOB
  3920.  
  3921.           If the referenced object has been blessed into a
  3922.           package, then    that package name is returned instead.
  3923.           You can think    of ref() as a typeof() operator.
  3924.  
  3925.               if (ref($r) eq "HASH") {
  3926.               print    "r is a    reference to a hash.\n";
  3927.               }
  3928.               if (!ref($r)) {
  3929.               print    "r is not a reference at all.\n";
  3930.               }
  3931.  
  3932.           See also the _p_e_r_l_r_e_f manpage.
  3933.  
  3934.       rename OLDNAME,NEWNAME
  3935.           Changes the name of a    file.  Returns 1 for success,
  3936.           0 otherwise.    Will not work across file system
  3937.           boundaries.
  3938.  
  3939.       require EXPR
  3940.  
  3941.       require Demands some semantics specified by EXPR, or by $_
  3942.           if EXPR is not supplied.  If EXPR is numeric,
  3943.           demands that the current version of Perl ($] or
  3944.           $PERL_VERSION) be equal or greater than EXPR.
  3945.  
  3946.           Otherwise, demands that a library file be included
  3947.           if it    hasn't already been included.  The file    is
  3948.           included via the do-FILE mechanism, which is
  3949.           essentially just a variety of    eval().     Has semantics
  3950.           similar to the following subroutine:
  3951.  
  3952.  
  3953.  
  3954.  
  3955.  
  3956.  
  3957.      Page 60                        (printed 10/23/98)
  3958.  
  3959.  
  3960.  
  3961.  
  3962.  
  3963.  
  3964.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3965.  
  3966.  
  3967.  
  3968.               sub require {
  3969.               my($filename)    = @_;
  3970.               return 1 if $INC{$filename};
  3971.               my($realfilename,$result);
  3972.               ITER:    {
  3973.                   foreach $prefix (@INC) {
  3974.                   $realfilename    = "$prefix/$filename";
  3975.                   if (-f $realfilename)    {
  3976.                       $result =    do $realfilename;
  3977.                       last ITER;
  3978.                   }
  3979.                   }
  3980.                   die "Can't find $filename    in \@INC";
  3981.               }
  3982.               die $@ if $@;
  3983.               die "$filename did not return    true value" unless $result;
  3984.               $INC{$filename} = $realfilename;
  3985.               return $result;
  3986.               }
  3987.  
  3988.           Note that the    file will not be included twice    under
  3989.           the same specified name.  The    file must return TRUE
  3990.           as the last statement    to indicate successful
  3991.           execution of any initialization code,    so it's
  3992.           customary to end such    a file with "1;" unless    you're
  3993.           sure it'll return TRUE otherwise.  But it's better
  3994.           just to put the "1;",    in case    you add    more
  3995.           statements.
  3996.  
  3997.           If EXPR is a bareword, the require assumes a "._p_m"
  3998.           extension and    replaces "::" with "/" in the filename
  3999.           for you, to make it easy to load standard modules.
  4000.           This form of loading of modules does not risk
  4001.           altering your    namespace.
  4002.  
  4003.           In other words, if you try this:
  4004.  
  4005.               require Foo::Bar;    # a splendid bareword
  4006.  
  4007.           The require function will actually look for the
  4008.           "_F_o_o/_B_a_r._p_m" file in the directories specified in
  4009.           the @INC array.
  4010.  
  4011.           But if you try this:
  4012.  
  4013.               $class = 'Foo::Bar';
  4014.               require $class;      # $class    is not a bareword
  4015.               #or
  4016.               require "Foo::Bar";  # not a bareword    because    of the ""
  4017.  
  4018.           The require function will look for the "_F_o_o::_B_a_r"
  4019.           file in the @INC array and will complain about not
  4020.  
  4021.  
  4022.  
  4023.      Page 61                        (printed 10/23/98)
  4024.  
  4025.  
  4026.  
  4027.  
  4028.  
  4029.  
  4030.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4031.  
  4032.  
  4033.  
  4034.           finding "_F_o_o::_B_a_r" there. In this case you can do:
  4035.  
  4036.               eval "require    $class";
  4037.  
  4038.           For a    yet-more-powerful import facility, see the use
  4039.           entry    elsewhere in this document and the _p_e_r_l_m_o_d
  4040.           manpage.
  4041.  
  4042.       reset    EXPR
  4043.  
  4044.       reset      Generally used in a continue block at    the end    of a
  4045.           loop to clear    variables and reset ?? searches    so
  4046.           that they work again.     The expression    is interpreted
  4047.           as a list of single characters (hyphens allowed for
  4048.           ranges).  All    variables and arrays beginning with
  4049.           one of those letters are reset to their pristine
  4050.           state.  If the expression is omitted,    one-match
  4051.           searches (?pattern?) are reset to match again.
  4052.           Resets only variables    or searches in the current
  4053.           package.  Always returns 1.  Examples:
  4054.  
  4055.               reset 'X';      # reset all X    variables
  4056.               reset 'a-z';      # reset lower    case variables
  4057.               reset;          # just reset ?? searches
  4058.  
  4059.           Resetting "A-Z" is not recommended because you'll
  4060.           wipe out your    @ARGV and @INC arrays and your %ENV
  4061.           hash.     Resets    only package variables--lexical
  4062.           variables are    unaffected, but    they clean themselves
  4063.           up on    scope exit anyway, so you'll probably want to
  4064.           use them instead.  See the my    entry elsewhere    in
  4065.           this document.
  4066.  
  4067.       return EXPR
  4068.  
  4069.       return  Returns from a subroutine, eval(), or    do FILE    with
  4070.           the value given in EXPR.  Evaluation of EXPR may be
  4071.           in list, scalar, or void context, depending on how
  4072.           the return value will    be used, and the context may
  4073.           vary from one    execution to the next (see
  4074.           wantarray()).     If no EXPR is given, returns an empty
  4075.           list in list context,    an undefined value in scalar
  4076.           context, or nothing in a void    context.
  4077.  
  4078.           (Note    that in    the absence of a return, a subroutine,
  4079.           eval,    or do FILE will    automatically return the value
  4080.           of the last expression evaluated.)
  4081.  
  4082.       reverse LIST
  4083.           In list context, returns a list value    consisting of
  4084.           the elements of LIST in the opposite order.  In
  4085.           scalar context, concatenates the elements of LIST,
  4086.  
  4087.  
  4088.  
  4089.      Page 62                        (printed 10/23/98)
  4090.  
  4091.  
  4092.  
  4093.  
  4094.  
  4095.  
  4096.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4097.  
  4098.  
  4099.  
  4100.           and returns a    string value consisting    of those
  4101.           bytes, but in    the opposite order.
  4102.  
  4103.               print reverse <>;          # line tac, last line    first
  4104.  
  4105.               undef $/;              # for    efficiency of <>
  4106.               print scalar reverse <>;      # byte tac, last line    tsrif
  4107.  
  4108.           This operator    is also    handy for inverting a hash,
  4109.           although there are some caveats.  If a value is
  4110.           duplicated in    the original hash, only    one of those
  4111.           can be represented as    a key in the inverted hash.
  4112.           Also,    this has to unwind one hash and    build a    whole
  4113.           new one, which may take some time on a large hash.
  4114.  
  4115.               %by_name = reverse %by_address;      # Invert the hash
  4116.  
  4117.  
  4118.       rewinddir DIRHANDLE
  4119.           Sets the current position to the beginning of    the
  4120.           directory for    the readdir() routine on DIRHANDLE.
  4121.  
  4122.       rindex STR,SUBSTR,POSITION
  4123.  
  4124.       rindex STR,SUBSTR
  4125.           Works    just like index    except that it returns the
  4126.           position of the LAST occurrence of SUBSTR in STR.
  4127.           If POSITION is specified, returns the    last
  4128.           occurrence at    or before that position.
  4129.  
  4130.       rmdir    FILENAME
  4131.  
  4132.       rmdir      Deletes the directory    specified by FILENAME if that
  4133.           directory is empty.  If it succeeds it returns TRUE,
  4134.           otherwise it returns FALSE and sets $! (errno).  If
  4135.           FILENAME is omitted, uses $_.
  4136.  
  4137.       s///      The substitution operator.  See the _p_e_r_l_o_p manpage.
  4138.  
  4139.       scalar EXPR
  4140.           Forces EXPR to be interpreted    in scalar context and
  4141.           returns the value of EXPR.
  4142.  
  4143.               @counts =    ( scalar @a, scalar @b,    scalar @c );
  4144.  
  4145.           There    is no equivalent operator to force an
  4146.           expression to    be interpolated    in list    context
  4147.           because it's in practice never needed.  If you
  4148.           really wanted    to do so, however, you could use the
  4149.           construction @{[ (some expression) ]}, but usually a
  4150.           simple (some expression) suffices.
  4151.  
  4152.  
  4153.  
  4154.  
  4155.      Page 63                        (printed 10/23/98)
  4156.  
  4157.  
  4158.  
  4159.  
  4160.  
  4161.  
  4162.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4163.  
  4164.  
  4165.  
  4166.       seek FILEHANDLE,POSITION,WHENCE
  4167.           Sets FILEHANDLE's position, just like    the fseek()
  4168.           call of stdio().  FILEHANDLE may be an expression
  4169.           whose    value gives the    name of    the filehandle.     The
  4170.           values for WHENCE are    0 to set the new position to
  4171.           POSITION, 1 to set it    to the current position    plus
  4172.           POSITION, and    2 to set it to EOF plus    POSITION
  4173.           (typically negative).     For WHENCE you    may use    the
  4174.           constants SEEK_SET, SEEK_CUR,    and SEEK_END from
  4175.           either the IO::Seekable or the POSIX module.
  4176.           Returns 1 upon success, 0 otherwise.
  4177.  
  4178.           If you want to position file for sysread() or
  4179.           syswrite(), don't use    seek() -- buffering makes its
  4180.           effect on the    file's system position unpredictable
  4181.           and non-portable.  Use sysseek() instead.
  4182.  
  4183.           On some systems you have to do a seek    whenever you
  4184.           switch between reading and writing.  Amongst other
  4185.           things, this may have    the effect of calling stdio's
  4186.           _c_l_e_a_r_e_r_r(3).    A WHENCE of 1 (SEEK_CUR) is useful for
  4187.           not moving the file position:
  4188.  
  4189.               seek(TEST,0,1);
  4190.  
  4191.           This is also useful for applications emulating tail
  4192.           -f.  Once you    hit EOF    on your    read, and then sleep
  4193.           for a    while, you might have to stick in a _s_e_e_k() to
  4194.           reset    things.     The seek() doesn't change the current
  4195.           position, but    it _d_o_e_s    clear the end-of-file
  4196.           condition on the handle, so that the next <FILE>
  4197.           makes    Perl try again to read something.  We hope.
  4198.  
  4199.           If that doesn't work (some stdios are    particularly
  4200.           cantankerous), then you may need something more like
  4201.           this:
  4202.  
  4203.               for (;;) {
  4204.               for ($curpos = tell(FILE); $_    = <FILE>;
  4205.                    $curpos = tell(FILE)) {
  4206.                   #    search for some    stuff and put it into files
  4207.               }
  4208.               sleep($for_a_while);
  4209.               seek(FILE, $curpos, 0);
  4210.               }
  4211.  
  4212.  
  4213.       seekdir DIRHANDLE,POS
  4214.           Sets the current position for    the readdir() routine
  4215.           on DIRHANDLE.     POS must be a value returned by
  4216.           telldir().  Has the same caveats about possible
  4217.           directory compaction as the corresponding system
  4218.  
  4219.  
  4220.  
  4221.      Page 64                        (printed 10/23/98)
  4222.  
  4223.  
  4224.  
  4225.  
  4226.  
  4227.  
  4228.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4229.  
  4230.  
  4231.  
  4232.           library routine.
  4233.  
  4234.       select FILEHANDLE
  4235.  
  4236.       select  Returns the currently    selected filehandle.  Sets the
  4237.           current default filehandle for output, if FILEHANDLE
  4238.           is supplied.    This has two effects: first, a write()
  4239.           or a print() without a filehandle will default to
  4240.           this FILEHANDLE.  Second, references to variables
  4241.           related to output will refer to this output channel.
  4242.           For example, if you have to set the top of form
  4243.           format for more than one output channel, you might
  4244.           do the following:
  4245.  
  4246.               select(REPORT1);
  4247.               $^ = 'report1_top';
  4248.               select(REPORT2);
  4249.               $^ = 'report2_top';
  4250.  
  4251.           FILEHANDLE may be an expression whose    value gives
  4252.           the name of the actual filehandle.  Thus:
  4253.  
  4254.               $oldfh = select(STDERR); $| = 1; select($oldfh);
  4255.  
  4256.           Some programmers may prefer to think of filehandles
  4257.           as objects with methods, preferring to write the
  4258.           last example as:
  4259.  
  4260.               use IO::Handle;
  4261.               STDERR->autoflush(1);
  4262.  
  4263.  
  4264.       select RBITS,WBITS,EBITS,TIMEOUT
  4265.           This calls the _s_e_l_e_c_t(2) system call with the    bit
  4266.           masks    specified, which can be    constructed using
  4267.           fileno() and vec(), along these lines:
  4268.  
  4269.               $rin = $win = $ein = '';
  4270.               vec($rin,fileno(STDIN),1)    = 1;
  4271.               vec($win,fileno(STDOUT),1) = 1;
  4272.               $ein = $rin | $win;
  4273.  
  4274.           If you want to select    on many    filehandles you    might
  4275.           wish to write    a subroutine:
  4276.  
  4277.  
  4278.  
  4279.  
  4280.  
  4281.  
  4282.  
  4283.  
  4284.  
  4285.  
  4286.  
  4287.      Page 65                        (printed 10/23/98)
  4288.  
  4289.  
  4290.  
  4291.  
  4292.  
  4293.  
  4294.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4295.  
  4296.  
  4297.  
  4298.               sub fhbits {
  4299.               my(@fhlist) =    split('    ',$_[0]);
  4300.               my($bits);
  4301.               for (@fhlist)    {
  4302.                   vec($bits,fileno($_),1) =    1;
  4303.               }
  4304.               $bits;
  4305.               }
  4306.               $rin = fhbits('STDIN TTY SOCK');
  4307.  
  4308.           The usual idiom is:
  4309.  
  4310.               ($nfound,$timeleft) =
  4311.             select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
  4312.  
  4313.           or to    block until something becomes ready just do
  4314.           this
  4315.  
  4316.               $nfound =    select($rout=$rin, $wout=$win, $eout=$ein, undef);
  4317.  
  4318.           Most systems do not bother to    return anything    useful
  4319.           in $timeleft,    so calling _s_e_l_e_c_t() in scalar context
  4320.           just returns $nfound.
  4321.  
  4322.           Any of the bit masks can also    be undef.  The
  4323.           timeout, if specified, is in seconds,    which may be
  4324.           fractional.  Note: not all implementations are
  4325.           capable of returning the$timeleft.  If not, they
  4326.           always return    $timeleft equal    to the supplied
  4327.           $timeout.
  4328.  
  4329.           You can effect a sleep of 250    milliseconds this way:
  4330.  
  4331.               select(undef, undef, undef, 0.25);
  4332.  
  4333.           WWWWAAAARRRRNNNNIIIINNNNGGGG: One should not attempt to mix buffered I/O
  4334.           (like    read() or <FH>)    with select(), except as
  4335.           permitted by POSIX, and even then only on POSIX
  4336.           systems.  You    have to    use sysread() instead.
  4337.  
  4338.       semctl ID,SEMNUM,CMD,ARG
  4339.           Calls    the System V IPC function semctl().  You'll
  4340.           probably have    to say
  4341.  
  4342.               use IPC::SysV;
  4343.  
  4344.           first    to get the correct constant definitions.  If
  4345.           CMD is IPC_STAT or GETALL, then ARG must be a
  4346.           variable which will hold the returned    semid_ds
  4347.           structure or semaphore value array.  Returns like
  4348.           ioctl(): the undefined value for error, "0 but true"
  4349.           for zero, or the actual return value otherwise.  See
  4350.  
  4351.  
  4352.  
  4353.      Page 66                        (printed 10/23/98)
  4354.  
  4355.  
  4356.  
  4357.  
  4358.  
  4359.  
  4360.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4361.  
  4362.  
  4363.  
  4364.           also IPC::SysV and IPC::Semaphore documentation.
  4365.  
  4366.       semget KEY,NSEMS,FLAGS
  4367.           Calls    the System V IPC function semget.  Returns the
  4368.           semaphore id,    or the undefined value if there    is an
  4369.           error.  See also IPC::SysV and IPC::SysV::Semaphore
  4370.           documentation.
  4371.  
  4372.       semop    KEY,OPSTRING
  4373.           Calls    the System V IPC function semop    to perform
  4374.           semaphore operations such as signaling and waiting.
  4375.           OPSTRING must    be a packed array of semop structures.
  4376.           Each semop structure can be generated    with
  4377.           pack("sss", $semnum, $semop, $semflag).  The number
  4378.           of semaphore operations is implied by    the length of
  4379.           OPSTRING.  Returns TRUE if successful, or FALSE if
  4380.           there    is an error.  As an example, the following
  4381.           code waits on    semaphore $semnum of semaphore id
  4382.           $semid:
  4383.  
  4384.               $semop = pack("sss", $semnum, -1,    0);
  4385.               die "Semaphore trouble: $!\n" unless semop($semid, $semop);
  4386.  
  4387.           To signal the    semaphore, replace -1 with 1.  See
  4388.           also IPC::SysV and IPC::SysV::Semaphore
  4389.           documentation.
  4390.  
  4391.       send SOCKET,MSG,FLAGS,TO
  4392.  
  4393.       send SOCKET,MSG,FLAGS
  4394.           Sends    a message on a socket.    Takes the same flags
  4395.           as the system    call of    the same name.    On unconnected
  4396.           sockets you must specify a destination to send TO,
  4397.           in which case    it does    a C sendto().  Returns the
  4398.           number of characters sent, or    the undefined value if
  4399.           there    is an error.  See the section on _U_D_P: _M_e_s_s_a_g_e
  4400.           _P_a_s_s_i_n_g in the _p_e_r_l_i_p_c manpage for examples.
  4401.  
  4402.       setpgrp PID,PGRP
  4403.           Sets the current process group for the specified
  4404.           PID, 0 for the current process.  Will    produce    a
  4405.           fatal    error if used on a machine that    doesn't
  4406.           implement _s_e_t_p_g_r_p(2).     If the    arguments are omitted,
  4407.           it defaults to 0,0.  Note that the POSIX version of
  4408.           setpgrp() does not accept any    arguments, so only
  4409.           setpgrp 0,0 is portable.
  4410.  
  4411.       setpriority WHICH,WHO,PRIORITY
  4412.           Sets the current priority for    a process, a process
  4413.           group, or a user.  (See _s_e_t_p_r_i_o_r_i_t_y(2).)  Will
  4414.           produce a fatal error    if used    on a machine that
  4415.           doesn't implement _s_e_t_p_r_i_o_r_i_t_y(2).
  4416.  
  4417.  
  4418.  
  4419.      Page 67                        (printed 10/23/98)
  4420.  
  4421.  
  4422.  
  4423.  
  4424.  
  4425.  
  4426.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4427.  
  4428.  
  4429.  
  4430.       setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
  4431.           Sets the socket option requested.  Returns undefined
  4432.           if there is an error.     OPTVAL    may be specified as
  4433.           undef    if you don't want to pass an argument.
  4434.  
  4435.       shift    ARRAY
  4436.  
  4437.       shift      Shifts the first value of the    array off and returns
  4438.           it, shortening the array by 1    and moving everything
  4439.           down.     If there are no elements in the array,
  4440.           returns the undefined    value.    If ARRAY is omitted,
  4441.           shifts the @_    array within the lexical scope of
  4442.           subroutines and formats, and the @ARGV array at file
  4443.           scopes or within the lexical scopes established by
  4444.           the eval '', BEGIN {}, END {}, and INIT {}
  4445.           constructs.  See also    unshift(), push(), and pop().
  4446.           Shift() and unshift()    do the same thing to the left
  4447.           end of an array that pop() and push()    do to the
  4448.           right    end.
  4449.  
  4450.       shmctl ID,CMD,ARG
  4451.           Calls    the System V IPC function shmctl.  You'll
  4452.           probably have    to say
  4453.  
  4454.               use IPC::SysV;
  4455.  
  4456.           first    to get the correct constant definitions.  If
  4457.           CMD is IPC_STAT, then    ARG must be a variable which
  4458.           will hold the    returned shmid_ds structure.  Returns
  4459.           like ioctl: the undefined value for error, "0    but
  4460.           true"    for zero, or the actual    return value
  4461.           otherwise.  See also IPC::SysV documentation.
  4462.  
  4463.       shmget KEY,SIZE,FLAGS
  4464.           Calls    the System V IPC function shmget.  Returns the
  4465.           shared memory    segment    id, or the undefined value if
  4466.           there    is an error.  See also IPC::SysV
  4467.           documentation.
  4468.  
  4469.       shmread ID,VAR,POS,SIZE
  4470.  
  4471.       shmwrite ID,STRING,POS,SIZE
  4472.           Reads    or writes the System V shared memory segment
  4473.           ID starting at position POS for size SIZE by
  4474.           attaching to it, copying in/out, and detaching from
  4475.           it.  When reading, VAR must be a variable that will
  4476.           hold the data    read.  When writing, if    STRING is too
  4477.           long,    only SIZE bytes    are used; if STRING is too
  4478.           short, nulls are written to fill out SIZE bytes.
  4479.           Return TRUE if successful, or    FALSE if there is an
  4480.           error.  See also IPC::SysV documentation.
  4481.  
  4482.  
  4483.  
  4484.  
  4485.      Page 68                        (printed 10/23/98)
  4486.  
  4487.  
  4488.  
  4489.  
  4490.  
  4491.  
  4492.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4493.  
  4494.  
  4495.  
  4496.       shutdown SOCKET,HOW
  4497.           Shuts    down a socket connection in the    manner
  4498.           indicated by HOW, which has the same interpretation
  4499.           as in    the system call    of the same name.
  4500.  
  4501.               shutdown(SOCKET, 0);    #    I/we have stopped reading data
  4502.               shutdown(SOCKET, 1);    #    I/we have stopped writing data
  4503.               shutdown(SOCKET, 2);    #    I/we have stopped using    this socket
  4504.  
  4505.           This is useful with sockets when you want to tell
  4506.           the other side you're    done writing but not done
  4507.           reading, or vice versa.  It's    also a more insistent
  4508.           form of close    because    it also    disables the
  4509.           filedescriptor in any    forked copies in other
  4510.           processes.
  4511.  
  4512.       sin EXPR
  4513.  
  4514.       sin      Returns the sine of EXPR (expressed in radians).  If
  4515.           EXPR is omitted, returns sine    of $_.
  4516.  
  4517.           For the inverse sine operation, you may use the
  4518.           POSIX::asin()    function, or use this relation:
  4519.  
  4520.               sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) }
  4521.  
  4522.  
  4523.       sleep    EXPR
  4524.  
  4525.       sleep      Causes the script to sleep for EXPR seconds, or
  4526.           forever if no    EXPR.  May be interrupted if the
  4527.           process receives a signal such as SIGALRM.  Returns
  4528.           the number of    seconds    actually slept.     You probably
  4529.           cannot mix alarm() and sleep() calls,    because
  4530.           sleep() is often implemented using alarm().
  4531.  
  4532.           On some older    systems, it may    sleep up to a full
  4533.           second less than what    you requested, depending on
  4534.           how it counts    seconds.  Most modern systems always
  4535.           sleep    the full amount.  They may appear to sleep
  4536.           longer than that, however, because your process
  4537.           might    not be scheduled right away in a busy
  4538.           multitasking system.
  4539.  
  4540.           For delays of    finer granularity than one second, you
  4541.           may use Perl's syscall() interface to    access
  4542.           _s_e_t_i_t_i_m_e_r(2) if your system supports it, or else see
  4543.           the select() entry elsewhere in this documentabove.
  4544.  
  4545.           See also the POSIX module's sigpause() function.
  4546.  
  4547.  
  4548.  
  4549.  
  4550.  
  4551.      Page 69                        (printed 10/23/98)
  4552.  
  4553.  
  4554.  
  4555.  
  4556.  
  4557.  
  4558.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4559.  
  4560.  
  4561.  
  4562.       socket SOCKET,DOMAIN,TYPE,PROTOCOL
  4563.           Opens    a socket of the    specified kind and attaches it
  4564.           to filehandle    SOCKET.     DOMAIN, TYPE, and PROTOCOL
  4565.           are specified    the same as for    the system call    of the
  4566.           same name.  You should "use Socket;" first to    get
  4567.           the proper definitions imported.  See    the example in
  4568.           the section on _S_o_c_k_e_t_s: _C_l_i_e_n_t/_S_e_r_v_e_r    _C_o_m_m_u_n_i_c_a_t_i_o_n
  4569.           in the _p_e_r_l_i_p_c manpage.
  4570.  
  4571.       socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
  4572.           Creates an unnamed pair of sockets in    the specified
  4573.           domain, of the specified type.  DOMAIN, TYPE,    and
  4574.           PROTOCOL are specified the same as for the system
  4575.           call of the same name.  If unimplemented, yields a
  4576.           fatal    error.    Returns    TRUE if    successful.
  4577.  
  4578.           Some systems defined pipe() in terms of
  4579.           socketpair(),    in which a call    to pipe(Rdr, Wtr) is
  4580.           essentially:
  4581.  
  4582.               use Socket;
  4583.               socketpair(Rdr, Wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
  4584.               shutdown(Rdr, 1);           # no more writing for reader
  4585.               shutdown(Wtr, 0);           # no more reading for writer
  4586.  
  4587.           See the _p_e_r_l_i_p_c manpage for an example of socketpair
  4588.           use.
  4589.  
  4590.       sort SUBNAME LIST
  4591.  
  4592.       sort BLOCK LIST
  4593.  
  4594.       sort LIST
  4595.           Sorts    the LIST and returns the sorted    list value.
  4596.           If SUBNAME or    BLOCK is omitted, sort()s in standard
  4597.           string comparison order.  If SUBNAME is specified,
  4598.           it gives the name of a subroutine that returns an
  4599.           integer less than, equal to, or greater than 0,
  4600.           depending on how the elements    of the array are to be
  4601.           ordered.  (The <=> and cmp operators are extremely
  4602.           useful in such routines.)  SUBNAME may be a scalar
  4603.           variable name    (unsubscripted), in which case the
  4604.           value    provides the name of (or a reference to) the
  4605.           actual subroutine to use.  In    place of a SUBNAME,
  4606.           you can provide a BLOCK as an    anonymous, in-line
  4607.           sort subroutine.
  4608.  
  4609.           In the interests of efficiency the normal calling
  4610.           code for subroutines is bypassed, with the following
  4611.           effects: the subroutine may not be a recursive
  4612.           subroutine, and the two elements to be compared are
  4613.           passed into the subroutine not via @_    but as the
  4614.  
  4615.  
  4616.  
  4617.      Page 70                        (printed 10/23/98)
  4618.  
  4619.  
  4620.  
  4621.  
  4622.  
  4623.  
  4624.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4625.  
  4626.  
  4627.  
  4628.           package global variables $a and $b (see example
  4629.           below).  They    are passed by reference, so don't
  4630.           modify $a and    $b.  And don't try to declare them as
  4631.           lexicals either.
  4632.  
  4633.           You also cannot exit out of the sort block or
  4634.           subroutine using any of the loop control operators
  4635.           described in the _p_e_r_l_s_y_n manpage or with goto().
  4636.  
  4637.           When use locale is in    effect,    sort LIST sorts    LIST
  4638.           according to the current collation locale.  See the
  4639.           _p_e_r_l_l_o_c_a_l_e manpage.
  4640.  
  4641.           Examples:
  4642.  
  4643.               #    sort lexically
  4644.               @articles    = sort @files;
  4645.  
  4646.               #    same thing, but    with explicit sort routine
  4647.               @articles    = sort {$a cmp $b} @files;
  4648.  
  4649.               #    now case-insensitively
  4650.               @articles    = sort {uc($a) cmp uc($b)} @files;
  4651.  
  4652.               #    same thing in reversed order
  4653.               @articles    = sort {$b cmp $a} @files;
  4654.  
  4655.               #    sort numerically ascending
  4656.               @articles    = sort {$a <=> $b} @files;
  4657.  
  4658.               #    sort numerically descending
  4659.               @articles    = sort {$b <=> $a} @files;
  4660.  
  4661.               #    sort using explicit subroutine name
  4662.               sub byage    {
  4663.               $age{$a} <=> $age{$b};  # presuming numeric
  4664.               }
  4665.               @sortedclass = sort byage    @class;
  4666.  
  4667.               #    this sorts the %age hash by value instead of key
  4668.               #    using an in-line function
  4669.               @eldest =    sort { $age{$b}    <=> $age{$a} } keys %age;
  4670.  
  4671.               sub backwards { $b cmp $a; }
  4672.               @harry = ('dog','cat','x','Cain','Abel');
  4673.               @george =    ('gone','chased','yz','Punished','Axed');
  4674.               print sort @harry;
  4675.                   #    prints AbelCaincatdogx
  4676.               print sort backwards @harry;
  4677.                   #    prints xdogcatCainAbel
  4678.               print sort @george, 'to',    @harry;
  4679.                   #    prints AbelAxedCainPunishedcatchaseddoggonetoxyz
  4680.  
  4681.  
  4682.  
  4683.      Page 71                        (printed 10/23/98)
  4684.  
  4685.  
  4686.  
  4687.  
  4688.  
  4689.  
  4690.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4691.  
  4692.  
  4693.  
  4694.               #    inefficiently sort by descending numeric compare using
  4695.               #    the first integer after    the first = sign, or the
  4696.               #    whole record case-insensitively    otherwise
  4697.  
  4698.               @new = sort {
  4699.               ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
  4700.                           ||
  4701.                       uc($a)  cmp  uc($b)
  4702.               }    @old;
  4703.  
  4704.               #    same thing, but    much more efficiently;
  4705.               #    we'll build auxiliary indices instead
  4706.               #    for speed
  4707.               @nums = @caps = ();
  4708.               for (@old) {
  4709.               push @nums, /=(\d+)/;
  4710.               push @caps, uc($_);
  4711.               }
  4712.  
  4713.               @new = @old[ sort    {
  4714.                       $nums[$b] <=>    $nums[$a]
  4715.                            ||
  4716.                       $caps[$a] cmp    $caps[$b]
  4717.                      } 0..$#old
  4718.                  ];
  4719.  
  4720.               #    same thing using a Schwartzian Transform (no temps)
  4721.               @new = map { $_->[0] }
  4722.               sort { $b->[1] <=> $a->[1]
  4723.                       ||
  4724.                  $a->[2] cmp $b->[2]
  4725.               } map    { [$_, /=(\d+)/, uc($_)] } @old;
  4726.  
  4727.           If you're using strict, you _M_U_S_T _N_O_T declare $a and
  4728.           $b as    lexicals.  They    are package globals.  That
  4729.           means    if you're in the main package, it's
  4730.  
  4731.               @articles    = sort {$main::b <=> $main::a} @files;
  4732.  
  4733.           or just
  4734.  
  4735.               @articles    = sort {$::b <=> $::a} @files;
  4736.  
  4737.           but if you're    in the FooPack package,    it's
  4738.  
  4739.               @articles    = sort {$FooPack::b <=>    $FooPack::a} @files;
  4740.  
  4741.           The comparison function is required to behave.  If
  4742.           it returns inconsistent results (sometimes saying
  4743.           $x[1]    is less    than $x[2] and sometimes saying    the
  4744.           opposite, for    example) the results are not well-
  4745.           defined.
  4746.  
  4747.  
  4748.  
  4749.      Page 72                        (printed 10/23/98)
  4750.  
  4751.  
  4752.  
  4753.  
  4754.  
  4755.  
  4756.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4757.  
  4758.  
  4759.  
  4760.       splice ARRAY,OFFSET,LENGTH,LIST
  4761.  
  4762.       splice ARRAY,OFFSET,LENGTH
  4763.  
  4764.       splice ARRAY,OFFSET
  4765.           Removes the elements designated by OFFSET and    LENGTH
  4766.           from an array, and replaces them with    the elements
  4767.           of LIST, if any.  In list context, returns the
  4768.           elements removed from    the array.  In scalar context,
  4769.           returns the last element removed, or undef if    no
  4770.           elements are removed.     The array grows or shrinks as
  4771.           necessary.  If OFFSET    is negative then it start that
  4772.           far from the end of the array.  If LENGTH is
  4773.           omitted, removes everything from OFFSET onward.  If
  4774.           LENGTH is negative, leave that many elements off the
  4775.           end of the array.  The following equivalences    hold
  4776.           (assuming $[ == 0):
  4777.  
  4778.               push(@a,$x,$y)      splice(@a,@a,0,$x,$y)
  4779.               pop(@a)          splice(@a,-1)
  4780.               shift(@a)          splice(@a,0,1)
  4781.               unshift(@a,$x,$y)      splice(@a,0,0,$x,$y)
  4782.               $a[$x] = $y      splice(@a,$x,1,$y)
  4783.  
  4784.           Example, assuming array lengths are passed before
  4785.           arrays:
  4786.  
  4787.               sub aeq {      # compare two    list values
  4788.               my(@a) = splice(@_,0,shift);
  4789.               my(@b) = splice(@_,0,shift);
  4790.               return 0 unless @a ==    @b;      # same len?
  4791.               while    (@a) {
  4792.                   return 0 if pop(@a) ne pop(@b);
  4793.               }
  4794.               return 1;
  4795.               }
  4796.               if (&aeq($len,@foo[1..$len],0+@bar,@bar))    { ... }
  4797.  
  4798.  
  4799.       split    /PATTERN/,EXPR,LIMIT
  4800.  
  4801.       split    /PATTERN/,EXPR
  4802.  
  4803.       split    /PATTERN/
  4804.  
  4805.       split      Splits a string into an array    of strings, and
  4806.           returns it.  By default, empty leading fields    are
  4807.           preserved, and empty trailing    ones are deleted.
  4808.  
  4809.           If not in list context, returns the number of    fields
  4810.           found    and splits into    the @_ array.  (In list
  4811.           context, you can force the split into    @_ by using ??
  4812.  
  4813.  
  4814.  
  4815.      Page 73                        (printed 10/23/98)
  4816.  
  4817.  
  4818.  
  4819.  
  4820.  
  4821.  
  4822.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4823.  
  4824.  
  4825.  
  4826.           as the pattern delimiters, but it still returns the
  4827.           list value.)    The use    of implicit split to @_    is
  4828.           deprecated, however, because it clobbers your
  4829.           subroutine arguments.
  4830.  
  4831.           If EXPR is omitted, splits the $_ string.  If
  4832.           PATTERN is also omitted, splits on whitespace    (after
  4833.           skipping any leading whitespace).  Anything matching
  4834.           PATTERN is taken to be a delimiter separating    the
  4835.           fields.  (Note that the delimiter may    be longer than
  4836.           one character.)
  4837.  
  4838.           If LIMIT is specified    and positive, splits into no
  4839.           more than that many fields (though it    may split into
  4840.           fewer).  If LIMIT is unspecified or zero, trailing
  4841.           null fields are stripped (which potential users of
  4842.           pop()    would do well to remember).  If    LIMIT is
  4843.           negative, it is treated as if    an arbitrarily large
  4844.           LIMIT    had been specified.
  4845.  
  4846.           A pattern matching the null string (not to be
  4847.           confused with    a null pattern //, which is just one
  4848.           member of the    set of patterns    matching a null
  4849.           string) will split the value of EXPR into separate
  4850.           characters at    each point it matches that way.     For
  4851.           example:
  4852.  
  4853.               print join(':', split(/ */, 'hi there'));
  4854.  
  4855.           produces the output 'h:i:t:h:e:r:e'.
  4856.  
  4857.           The LIMIT parameter can be used to split a line
  4858.           partially
  4859.  
  4860.               ($login, $passwd,    $remainder) = split(/:/, $_, 3);
  4861.  
  4862.           When assigning to a list, if LIMIT is    omitted, Perl
  4863.           supplies a LIMIT one larger than the number of
  4864.           variables in the list, to avoid unnecessary work.
  4865.           For the list above LIMIT would have been 4 by
  4866.           default.  In time critical applications it behooves
  4867.           you not to split into    more fields than you really
  4868.           need.
  4869.  
  4870.           If the PATTERN contains parentheses, additional
  4871.           array    elements are created from each matching
  4872.           substring in the delimiter.
  4873.  
  4874.               split(/([,-])/, "1-10,20", 3);
  4875.  
  4876.           produces the list value
  4877.  
  4878.  
  4879.  
  4880.  
  4881.      Page 74                        (printed 10/23/98)
  4882.  
  4883.  
  4884.  
  4885.  
  4886.  
  4887.  
  4888.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4889.  
  4890.  
  4891.  
  4892.               (1, '-', 10, ',',    20)
  4893.  
  4894.           If you had the entire    header of a normal Unix    email
  4895.           message in $header, you could    split it up into
  4896.           fields and their values this way:
  4897.  
  4898.               $header =~ s/\n\s+/ /g;  # fix continuation lines
  4899.               %hdrs   =     (UNIX_FROM => split /^(\S*?):\s*/m, $header);
  4900.  
  4901.           The pattern /PATTERN/    may be replaced    with an
  4902.           expression to    specify    patterns that vary at runtime.
  4903.           (To do runtime compilation only once,    use
  4904.           /$variable/o.)
  4905.  
  4906.           As a special case, specifying    a PATTERN of space ('
  4907.           ') will split    on white space just as split() with no
  4908.           arguments does.  Thus, split(' ') can    be used    to
  4909.           emulate aaaawwwwkkkk's    default    behavior, whereas split(/ /)
  4910.           will give you    as many    null initial fields as there
  4911.           are leading spaces.  A split() on /\s+/ is like a
  4912.           split(' ') except that any leading whitespace
  4913.           produces a null first    field.    A split() with no
  4914.           arguments really does    a split(' ', $_) internally.
  4915.  
  4916.           Example:
  4917.  
  4918.               open(PASSWD, '/etc/passwd');
  4919.               while (<PASSWD>) {
  4920.               ($login, $passwd, $uid, $gid,
  4921.                $gcos, $home, $shell) = split(/:/);
  4922.               #...
  4923.               }
  4924.  
  4925.           (Note    that $shell above will still have a newline on
  4926.           it.  See the chop, chomp,  and join entries
  4927.           elsewhere in this document.)
  4928.  
  4929.       sprintf FORMAT, LIST
  4930.           Returns a string formatted by    the usual printf()
  4931.           conventions of the C library function    sprintf().
  4932.           See the _s_p_r_i_n_t_f(_3) manpage or    the _p_r_i_n_t_f(_3) manpage
  4933.           on your system for an    explanation of the general
  4934.           principles.
  4935.  
  4936.           Perl does its    own sprintf() formatting -- it
  4937.           emulates the C function sprintf(), but it doesn't
  4938.           use it (except for floating-point numbers, and even
  4939.           then only the    standard modifiers are allowed).  As a
  4940.           result, any non-standard extensions in your local
  4941.           sprintf() are    not available from Perl.
  4942.  
  4943.           Perl's sprintf() permits the following universally-
  4944.  
  4945.  
  4946.  
  4947.      Page 75                        (printed 10/23/98)
  4948.  
  4949.  
  4950.  
  4951.  
  4952.  
  4953.  
  4954.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  4955.  
  4956.  
  4957.  
  4958.           known    conversions:
  4959.  
  4960.              %%      a percent sign
  4961.              %c      a character with the given number
  4962.              %s      a string
  4963.              %d      a signed integer, in decimal
  4964.              %u      an unsigned integer, in decimal
  4965.              %o      an unsigned integer, in octal
  4966.              %x      an unsigned integer, in hexadecimal
  4967.              %e      a floating-point number, in scientific notation
  4968.              %f      a floating-point number, in fixed decimal notation
  4969.              %g      a floating-point number, in %e or %f notation
  4970.  
  4971.           In addition, Perl permits the    following widely-
  4972.           supported conversions:
  4973.  
  4974.              %X      like %x, but using upper-case    letters
  4975.              %E      like %e, but using an    upper-case "E"
  4976.              %G      like %g, but with an upper-case "E" (if applicable)
  4977.              %p      a pointer (outputs the Perl value's address in hexadecimal)
  4978.              %n      special: *stores* the    number of characters output so far
  4979.               into the next    variable in the    parameter list
  4980.  
  4981.           Finally, for backward    (and we    do mean    "backward")
  4982.           compatibility, Perl permits these unnecessary    but
  4983.           widely-supported conversions:
  4984.  
  4985.              %i      a synonym for    %d
  4986.              %D      a synonym for    %ld
  4987.              %U      a synonym for    %lu
  4988.              %O      a synonym for    %lo
  4989.              %F      a synonym for    %f
  4990.  
  4991.           Perl permits the following universally-known flags
  4992.           between the %    and the    conversion letter:
  4993.  
  4994.              space   prefix positive number with a space
  4995.              +         prefix positive number with a plus    sign
  4996.              -         left-justify within the field
  4997.              0         use zeros,    not spaces, to right-justify
  4998.              #         prefix non-zero octal with    "0", non-zero hex with "0x"
  4999.              number  minimum field width
  5000.              .number "precision": digits after decimal point for
  5001.                  floating-point, max length    for string, minimum length
  5002.                  for integer
  5003.              l         interpret integer as C type "long"    or "unsigned long"
  5004.              h         interpret integer as C type "short" or "unsigned short"
  5005.  
  5006.           There    is also    one Perl-specific flag:
  5007.  
  5008.              V         interpret integer as Perl's standard integer type
  5009.  
  5010.  
  5011.  
  5012.  
  5013.      Page 76                        (printed 10/23/98)
  5014.  
  5015.  
  5016.  
  5017.  
  5018.  
  5019.  
  5020.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5021.  
  5022.  
  5023.  
  5024.           Where    a number would appear in the flags, an
  5025.           asterisk ("*") may be    used instead, in which case
  5026.           Perl uses the    next item in the parameter list    as the
  5027.           given    number (that is, as the    field width or
  5028.           precision).  If a field width    obtained through "*"
  5029.           is negative, it has the same effect as the "-" flag:
  5030.           left-justification.
  5031.  
  5032.           If use locale    is in effect, the character used for
  5033.           the decimal point in formatted real numbers is
  5034.           affected by the LC_NUMERIC locale.  See the
  5035.           _p_e_r_l_l_o_c_a_l_e manpage.
  5036.  
  5037.       sqrt EXPR
  5038.  
  5039.       sqrt      Return the square root of EXPR.  If EXPR is omitted,
  5040.           returns square root of $_.
  5041.  
  5042.       srand    EXPR
  5043.  
  5044.       srand      Sets the random number seed for the rand() operator.
  5045.           If EXPR is omitted, uses a semi-random value based
  5046.           on the current time and process ID, among other
  5047.           things.  In versions of Perl prior to    5.004 the
  5048.           default seed was just    the current time().  This
  5049.           isn't    a particularly good seed, so many old programs
  5050.           supply their own seed    value (often time ^ $$ or time
  5051.           ^ ($$    + ($$ << 15))),    but that isn't necessary any
  5052.           more.
  5053.  
  5054.           In fact, it's    usually    not necessary to call srand()
  5055.           at all, because if it    is not called explicitly, it
  5056.           is called implicitly at the first use    of the rand()
  5057.           operator.  However, this was not the case in version
  5058.           of Perl before 5.004,    so if your script will run
  5059.           under    older Perl versions, it    should call srand().
  5060.  
  5061.           Note that you    need something much more random    than
  5062.           the default seed for cryptographic purposes.
  5063.           Checksumming the compressed output of    one or more
  5064.           rapidly changing operating system status programs is
  5065.           the usual method.  For example:
  5066.  
  5067.               srand (time ^ $$ ^ unpack    "%L*", `ps axww    | gzip`);
  5068.  
  5069.           If you're particularly concerned with    this, see the
  5070.           Math::TrulyRandom module in CPAN.
  5071.  
  5072.           Do _n_o_t call srand() multiple times in    your program
  5073.           unless you know exactly what you're doing and    why
  5074.           you're doing it.  The    point of the function is to
  5075.           "seed" the rand() function so    that rand() can
  5076.  
  5077.  
  5078.  
  5079.      Page 77                        (printed 10/23/98)
  5080.  
  5081.  
  5082.  
  5083.  
  5084.  
  5085.  
  5086.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5087.  
  5088.  
  5089.  
  5090.           produce a different sequence each time you run your
  5091.           program.  Just do it once at the top of your
  5092.           program, or you _w_o_n'_t    get random numbers out of
  5093.           rand()!
  5094.  
  5095.           Frequently called programs (like CGI scripts)    that
  5096.           simply use
  5097.  
  5098.               time ^ $$
  5099.  
  5100.           for a    seed can fall prey to the mathematical
  5101.           property that
  5102.  
  5103.               a^b == (a+1)^(b+1)
  5104.  
  5105.           one-third of the time.  So don't do that.
  5106.  
  5107.       stat FILEHANDLE
  5108.  
  5109.       stat EXPR
  5110.  
  5111.       stat      Returns a 13-element list giving the status info for
  5112.           a file, either the file opened via FILEHANDLE, or
  5113.           named    by EXPR.  If EXPR is omitted, it stats $_.
  5114.           Returns a null list if the stat fails.  Typically
  5115.           used as follows:
  5116.  
  5117.               ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  5118.              $atime,$mtime,$ctime,$blksize,$blocks)
  5119.                  = stat($filename);
  5120.  
  5121.           Not all fields are supported on all filesystem
  5122.           types.  Here are the meaning of the fields:
  5123.  
  5124.             0 dev      device number of    filesystem
  5125.             1 ino      inode number
  5126.             2 mode     file mode  (type    and permissions)
  5127.             3 nlink    number of (hard)    links to the file
  5128.             4 uid      numeric user ID of file's owner
  5129.             5 gid      numeric group ID    of file's owner
  5130.             6 rdev     the device identifier (special files only)
  5131.             7 size     total size of file, in bytes
  5132.             8 atime    last access time    since the epoch
  5133.             9 mtime    last modify time    since the epoch
  5134.            10 ctime    inode change time (NOT creation time!) since the    epoch
  5135.            11 blksize  preferred block size for    file system I/O
  5136.            12 blocks   actual number of    blocks allocated
  5137.  
  5138.           (The epoch was at 00:00 January 1, 1970 GMT.)
  5139.  
  5140.           If stat is passed the    special    filehandle consisting
  5141.           of an    underline, no stat is done, but    the current
  5142.  
  5143.  
  5144.  
  5145.      Page 78                        (printed 10/23/98)
  5146.  
  5147.  
  5148.  
  5149.  
  5150.  
  5151.  
  5152.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5153.  
  5154.  
  5155.  
  5156.           contents of the stat structure from the last stat or
  5157.           filetest are returned.  Example:
  5158.  
  5159.               if (-x $file && (($d) = stat(_)) && $d < 0) {
  5160.               print    "$file is executable NFS file\n";
  5161.               }
  5162.  
  5163.           (This    works on machines only for which the device
  5164.           number is negative under NFS.)
  5165.  
  5166.           In scalar context, stat() returns a boolean value
  5167.           indicating success or    failure, and, if successful,
  5168.           sets the information associated with the special
  5169.           filehandle _.
  5170.  
  5171.       study    SCALAR
  5172.  
  5173.       study      Takes    extra time to study SCALAR ($_ if unspecified)
  5174.           in anticipation of doing many    pattern    matches    on the
  5175.           string before    it is next modified.  This may or may
  5176.           not save time, depending on the nature and number of
  5177.           patterns you are searching on, and on    the
  5178.           distribution of character frequencies    in the string
  5179.           to be    searched -- you    probably want to compare run
  5180.           times    with and without it to see which runs faster.
  5181.           Those    loops which scan for many short    constant
  5182.           strings (including the constant parts    of more
  5183.           complex patterns) will benefit most.    You may    have
  5184.           only one study() active at a time -- if you study a
  5185.           different scalar the first is    "unstudied".  (The way
  5186.           study() works    is this: a linked list of every
  5187.           character in the string to be    searched is made, so
  5188.           we know, for example,    where all the 'k' characters
  5189.           are.    From each search string, the rarest character
  5190.           is selected, based on    some static frequency tables
  5191.           constructed from some    C programs and English text.
  5192.           Only those places that contain this "rarest"
  5193.           character are    examined.)
  5194.  
  5195.           For example, here is a loop that inserts index
  5196.           producing entries before any line containing a
  5197.           certain pattern:
  5198.  
  5199.               while (<>) {
  5200.               study;
  5201.               print    ".IX foo\n" if /\bfoo\b/;
  5202.               print    ".IX bar\n" if /\bbar\b/;
  5203.               print    ".IX blurfl\n" if /\bblurfl\b/;
  5204.               # ...
  5205.               print;
  5206.               }
  5207.  
  5208.  
  5209.  
  5210.  
  5211.      Page 79                        (printed 10/23/98)
  5212.  
  5213.  
  5214.  
  5215.  
  5216.  
  5217.  
  5218.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5219.  
  5220.  
  5221.  
  5222.           In searching for /\bfoo\b/, only those locations in
  5223.           $_ that contain "f" will be looked at, because "f"
  5224.           is rarer than    "o".  In general, this is a big    win
  5225.           except in pathological cases.     The only question is
  5226.           whether it saves you more time than it took to build
  5227.           the linked list in the first place.
  5228.  
  5229.           Note that if you have    to look    for strings that you
  5230.           don't    know till runtime, you can build an entire
  5231.           loop as a string and eval() that to avoid
  5232.           recompiling all your patterns    all the    time.
  5233.           Together with    undefining $/ to input entire files as
  5234.           one record, this can be very fast, often faster than
  5235.           specialized programs like _f_g_r_e_p(1).  The following
  5236.           scans    a list of files    (@files) for a list of words
  5237.           (@words), and    prints out the names of    those files
  5238.           that contain a match:
  5239.  
  5240.               $search =    'while (<>) { study;';
  5241.               foreach $word (@words) {
  5242.               $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n";
  5243.               }
  5244.               $search .= "}";
  5245.               @ARGV = @files;
  5246.               undef $/;
  5247.               eval $search;          # this screams
  5248.               $/ = "\n";      # put    back to    normal input delimiter
  5249.               foreach $file (sort keys(%seen)) {
  5250.               print    $file, "\n";
  5251.               }
  5252.  
  5253.  
  5254.       sub BLOCK
  5255.  
  5256.       sub NAME
  5257.  
  5258.       sub NAME BLOCK
  5259.           This is subroutine definition, not a real function
  5260.           _p_e_r _s_e.  With    just a NAME (and possibly prototypes),
  5261.           it's just a forward declaration.  Without a NAME,
  5262.           it's an anonymous function declaration, and does
  5263.           actually return a value: the CODE ref    of the closure
  5264.           you just created.  See the _p_e_r_l_s_u_b manpage and the
  5265.           _p_e_r_l_r_e_f manpage for details.
  5266.  
  5267.       substr EXPR,OFFSET,LEN,REPLACEMENT
  5268.  
  5269.       substr EXPR,OFFSET,LEN
  5270.  
  5271.       substr EXPR,OFFSET
  5272.           Extracts a substring out of EXPR and returns it.
  5273.           First    character is at    offset 0, or whatever you've
  5274.  
  5275.  
  5276.  
  5277.      Page 80                        (printed 10/23/98)
  5278.  
  5279.  
  5280.  
  5281.  
  5282.  
  5283.  
  5284.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5285.  
  5286.  
  5287.  
  5288.           set $[ to (but don't do that).  If OFFSET is
  5289.           negative (or more precisely, less than $[), starts
  5290.           that far from    the end    of the string.    If LEN is
  5291.           omitted, returns everything to the end of the
  5292.           string.  If LEN is negative, leaves that many
  5293.           characters off the end of the    string.
  5294.  
  5295.           If you specify a substring that is partly outside
  5296.           the string, the part within the string is returned.
  5297.           If the substring is totally outside the string a
  5298.           warning is produced.
  5299.  
  5300.           You can use the substr() function as an lvalue, in
  5301.           which    case EXPR must be an lvalue.  If you assign
  5302.           something shorter than LEN, the string will shrink,
  5303.           and if you assign something longer than LEN, the
  5304.           string will grow to accommodate it.  To keep the
  5305.           string the same length you may need to pad or    chop
  5306.           your value using sprintf().
  5307.  
  5308.           An alternative to using substr() as an lvalue    is to
  5309.           specify the replacement string as the    4th argument.
  5310.           This allows you to replace parts of the EXPR and
  5311.           return what was there    before in one operation.
  5312.  
  5313.       symlink OLDFILE,NEWFILE
  5314.           Creates a new    filename symbolically linked to    the
  5315.           old filename.     Returns 1 for success,    0 otherwise.
  5316.           On systems that don't    support    symbolic links,
  5317.           produces a fatal error at run    time.  To check    for
  5318.           that,    use eval:
  5319.  
  5320.               $symlink_exists =     eval {    symlink("","");    1 };
  5321.  
  5322.  
  5323.       syscall LIST
  5324.           Calls    the system call    specified as the first element
  5325.           of the list, passing the remaining elements as
  5326.           arguments to the system call.     If unimplemented,
  5327.           produces a fatal error.  The arguments are
  5328.           interpreted as follows: if a given argument is
  5329.           numeric, the argument    is passed as an    int.  If not,
  5330.           the pointer to the string value is passed.  You are
  5331.           responsible to make sure a string is pre-extended
  5332.           long enough to receive any result that might be
  5333.           written into a string.  You can't use    a string
  5334.           literal (or other read-only string) as an argument
  5335.           to syscall() because Perl has    to assume that any
  5336.           string pointer might be written through.  If your
  5337.           integer arguments are    not literals and have never
  5338.           been interpreted in a    numeric    context, you may need
  5339.           to add 0 to them to force them to look like numbers.
  5340.  
  5341.  
  5342.  
  5343.      Page 81                        (printed 10/23/98)
  5344.  
  5345.  
  5346.  
  5347.  
  5348.  
  5349.  
  5350.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5351.  
  5352.  
  5353.  
  5354.           This emulates    the syswrite() function    (or vice
  5355.           versa):
  5356.  
  5357.               require 'syscall.ph';          # may    need to    run h2ph
  5358.               $s = "hi there\n";
  5359.               syscall(&SYS_write, fileno(STDOUT), $s, length $s);
  5360.  
  5361.           Note that Perl supports passing of up    to only    14
  5362.           arguments to your system call, which in practice
  5363.           should usually suffice.
  5364.  
  5365.           Syscall returns whatever value returned by the
  5366.           system call it calls.     If the    system call fails,
  5367.           syscall() returns -1 and sets    $! (errno).  Note that
  5368.           some system calls can    legitimately return -1.     The
  5369.           proper way to    handle such calls is to    assign $!=0;
  5370.           before the call and check the    value of $! if syscall
  5371.           returns -1.
  5372.  
  5373.           There's a problem with syscall(&SYS_pipe): it
  5374.           returns the file number of the read end of the pipe
  5375.           it creates.  There is    no way to retrieve the file
  5376.           number of the    other end.  You    can avoid this problem
  5377.           by using pipe() instead.
  5378.  
  5379.       sysopen FILEHANDLE,FILENAME,MODE
  5380.  
  5381.       sysopen FILEHANDLE,FILENAME,MODE,PERMS
  5382.           Opens    the file whose filename    is given by FILENAME,
  5383.           and associates it with FILEHANDLE.  If FILEHANDLE is
  5384.           an expression, its value is used as the name of the
  5385.           real filehandle wanted.  This    function calls the
  5386.           underlying operating system's    open() function    with
  5387.           the parameters FILENAME, MODE, PERMS.
  5388.  
  5389.           The possible values and flag bits of the MODE
  5390.           parameter are    system-dependent; they are available
  5391.           via the standard module Fcntl.  For historical
  5392.           reasons, some    values work on almost every system
  5393.           supported by perl: zero means    read-only, one means
  5394.           write-only, and two means read/write.     We know that
  5395.           these    values do _n_o_t work under OS/390    Unix and on
  5396.           the Macintosh; you probably don't want to use    them
  5397.           in new code.
  5398.  
  5399.           If the file named by FILENAME    does not exist and the
  5400.           open() call creates it (typically because MODE
  5401.           includes the O_CREAT flag), then the value of    PERMS
  5402.           specifies the    permissions of the newly created file.
  5403.           If you omit the PERMS    argument to sysopen(), Perl
  5404.           uses the octal value 0666.  These permission values
  5405.           need to be in    octal, and are modified    by your
  5406.  
  5407.  
  5408.  
  5409.      Page 82                        (printed 10/23/98)
  5410.  
  5411.  
  5412.  
  5413.  
  5414.  
  5415.  
  5416.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5417.  
  5418.  
  5419.  
  5420.           process's current umask.  The    umask value is a
  5421.           number representing disabled permissions bits--if
  5422.           your umask were 027 (group can't write; others can't
  5423.           read,    write, or execute), then passing sysopen()
  5424.           0666 would create a file with    mode 0640 (0666    &~ 027
  5425.           is 0640).
  5426.  
  5427.           If you find this umask() talk    confusing, here's some
  5428.           advice: supply a creation mode of 0666 for regular
  5429.           files    and one    of 0777    for directories    (in mkdir())
  5430.           and executable files.     This gives users the freedom
  5431.           of choice: if    they want protected files, they    might
  5432.           choose process umasks    of 022,    027, or    even the
  5433.           particularly antisocial mask of 077.    Programs
  5434.           should rarely    if ever    make policy decisions better
  5435.           left to the user.  The exception to this is when
  5436.           writing files    that should be kept private:  mail
  5437.           files, web browser cookies, ._r_h_o_s_t_s files, and so
  5438.           on.  In short, seldom    if ever    use 0644 as argument
  5439.           to sysopen() because that takes away the user's
  5440.           option to have a more    permissive umask.  Better to
  5441.           omit it.
  5442.  
  5443.           The IO::File module provides a more object-oriented
  5444.           approach, if you're into that    kind of    thing.
  5445.  
  5446.       sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
  5447.  
  5448.       sysread FILEHANDLE,SCALAR,LENGTH
  5449.           Attempts to read LENGTH bytes    of data    into variable
  5450.           SCALAR from the specified FILEHANDLE,    using the
  5451.           system call _r_e_a_d(2).    It bypasses stdio, so mixing
  5452.           this with other kinds    of reads, print(), write(),
  5453.           seek(), or tell() can    cause confusion    because    stdio
  5454.           usually buffers data.     Returns the number of bytes
  5455.           actually read, 0 at end of file, or undef if there
  5456.           was an error.     SCALAR    will be    grown or shrunk    so
  5457.           that the last    byte actually read is the last byte of
  5458.           the scalar after the read.
  5459.  
  5460.           An OFFSET may    be specified to    place the read data at
  5461.           some place in    the string other than the beginning.
  5462.           A negative OFFSET specifies placement    at that    many
  5463.           bytes    counting backwards from    the end    of the string.
  5464.           A positive OFFSET greater than the length of SCALAR
  5465.           results in the string    being padded to    the required
  5466.           size with "\0" bytes before the result of the    read
  5467.           is appended.
  5468.  
  5469.       sysseek FILEHANDLE,POSITION,WHENCE
  5470.           Sets FILEHANDLE's system position using the system
  5471.           call _l_s_e_e_k(2).  It bypasses stdio, so    mixing this
  5472.  
  5473.  
  5474.  
  5475.      Page 83                        (printed 10/23/98)
  5476.  
  5477.  
  5478.  
  5479.  
  5480.  
  5481.  
  5482.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5483.  
  5484.  
  5485.  
  5486.           with reads (other than sysread()), print(), write(),
  5487.           seek(), or tell() may    cause confusion.  FILEHANDLE
  5488.           may be an expression whose value gives the name of
  5489.           the filehandle.  The values for WHENCE are 0 to set
  5490.           the new position to POSITION,    1 to set the it    to the
  5491.           current position plus    POSITION, and 2    to set it to
  5492.           EOF plus POSITION (typically negative).  For WHENCE,
  5493.           you may use the constants SEEK_SET, SEEK_CUR,    and
  5494.           SEEK_END from    either the IO::Seekable    or the POSIX
  5495.           module.
  5496.  
  5497.           Returns the new position, or the undefined value on
  5498.           failure.  A position of zero is returned as the
  5499.           string "0 but    true"; thus sysseek() returns TRUE on
  5500.           success and FALSE on failure,    yet you    can still
  5501.           easily determine the new position.
  5502.  
  5503.       system LIST
  5504.  
  5505.       system PROGRAM LIST
  5506.           Does exactly the same    thing as "exec LIST" except
  5507.           that a fork is done first, and the parent process
  5508.           waits    for the    child process to complete.  Note that
  5509.           argument processing varies depending on the number
  5510.           of arguments.     If there is more than one argument in
  5511.           LIST,    or if LIST is an array with more than one
  5512.           value, starts    the program given by the first element
  5513.           of the list with arguments given by the rest of the
  5514.           list.     If there is only one scalar argument, the
  5515.           argument is checked for shell    metacharacters,    and if
  5516.           there    are any, the entire argument is    passed to the
  5517.           system's command shell for parsing (this is /bin/sh
  5518.           -c on    Unix platforms,    but varies on other
  5519.           platforms).  If there    are no shell metacharacters in
  5520.           the argument,    it is split into words and passed
  5521.           directly to execvp(),    which is more efficient.
  5522.  
  5523.           The return value is the exit status of the program
  5524.           as returned by the wait() call.  To get the actual
  5525.           exit value divide by 256.  See also the exec entry
  5526.           elsewhere in this document.  This is _N_O_T what    you
  5527.           want to use to capture the output from a command,
  5528.           for that you should use merely backticks or qx//, as
  5529.           described in the section on `_S_T_R_I_N_G` in the _p_e_r_l_o_p
  5530.           manpage.
  5531.  
  5532.           Like exec(), system()    allows you to lie to a program
  5533.           about    its name if you    use the    "system    PROGRAM    LIST"
  5534.           syntax.  Again, see the exec entry elsewhere in this
  5535.           document.
  5536.  
  5537.           Because system() and backticks block SIGINT and
  5538.  
  5539.  
  5540.  
  5541.      Page 84                        (printed 10/23/98)
  5542.  
  5543.  
  5544.  
  5545.  
  5546.  
  5547.  
  5548.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5549.  
  5550.  
  5551.  
  5552.           SIGQUIT, killing the program they're running doesn't
  5553.           actually interrupt your program.
  5554.  
  5555.               @args = ("command", "arg1", "arg2");
  5556.               system(@args) == 0
  5557.                or die "system @args    failed:    $?"
  5558.  
  5559.           You can check    all the    failure    possibilities by
  5560.           inspecting $?    like this:
  5561.  
  5562.               $exit_value  = $?    >> 8;
  5563.               $signal_num  = $?    & 127;
  5564.               $dumped_core = $?    & 128;
  5565.  
  5566.           When the arguments get executed via the system
  5567.           shell, results and return codes will be subject to
  5568.           its quirks and capabilities.    See the    section    on
  5569.           `_S_T_R_I_N_G` in the _p_e_r_l_o_p manpage and the exec entry
  5570.           elsewhere in this documentfor    details.
  5571.  
  5572.       syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
  5573.  
  5574.       syswrite FILEHANDLE,SCALAR,LENGTH
  5575.           Attempts to write LENGTH bytes of data from variable
  5576.           SCALAR to the    specified FILEHANDLE, using the    system
  5577.           call _w_r_i_t_e(2).  It bypasses stdio, so    mixing this
  5578.           with reads (other than sysread()), print(), write(),
  5579.           seek(), or tell() may    cause confusion    because    stdio
  5580.           usually buffers data.     Returns the number of bytes
  5581.           actually written, or undef if    there was an error.
  5582.           If the LENGTH    is greater than    the available data in
  5583.           the SCALAR after the OFFSET, only as much data as is
  5584.           available will be written.
  5585.  
  5586.           An OFFSET may    be specified to    write the data from
  5587.           some part of the string other    than the beginning.  A
  5588.           negative OFFSET specifies writing that many bytes
  5589.           counting backwards from the end of the string.  In
  5590.           the case the SCALAR is empty you can use OFFSET but
  5591.           only zero offset.
  5592.  
  5593.       tell FILEHANDLE
  5594.  
  5595.       tell      Returns the current position for FILEHANDLE.
  5596.           FILEHANDLE may be an expression whose    value gives
  5597.           the name of the actual filehandle.  If FILEHANDLE is
  5598.           omitted, assumes the file last read.
  5599.  
  5600.       telldir DIRHANDLE
  5601.           Returns the current position of the readdir()
  5602.           routines on DIRHANDLE.  Value    may be given to
  5603.           seekdir() to access a    particular location in a
  5604.  
  5605.  
  5606.  
  5607.      Page 85                        (printed 10/23/98)
  5608.  
  5609.  
  5610.  
  5611.  
  5612.  
  5613.  
  5614.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5615.  
  5616.  
  5617.  
  5618.           directory.  Has the same caveats about possible
  5619.           directory compaction as the corresponding system
  5620.           library routine.
  5621.  
  5622.       tie VARIABLE,CLASSNAME,LIST
  5623.           This function    binds a    variable to a package class
  5624.           that will provide the    implementation for the
  5625.           variable.  VARIABLE is the name of the variable to
  5626.           be enchanted.     CLASSNAME is the name of a class
  5627.           implementing objects of correct type.     Any
  5628.           additional arguments are passed to the "new()"
  5629.           method of the    class (meaning TIESCALAR, TIEARRAY, or
  5630.           TIEHASH).  Typically these are arguments such    as
  5631.           might    be passed to the dbm_open() function of    C.
  5632.           The object returned by the "new()" method is also
  5633.           returned by the tie()    function, which    would be
  5634.           useful if you    want to    access other methods in
  5635.           CLASSNAME.
  5636.  
  5637.           Note that functions such as keys() and values() may
  5638.           return huge lists when used on large objects,    like
  5639.           DBM files.  You may prefer to    use the    each()
  5640.           function to iterate over such.  Example:
  5641.  
  5642.               #    print out history file offsets
  5643.               use NDBM_File;
  5644.               tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
  5645.               while (($key,$val) = each    %HIST) {
  5646.               print    $key, '    = ', unpack('L',$val), "\n";
  5647.               }
  5648.               untie(%HIST);
  5649.  
  5650.           A class implementing a hash should have the
  5651.           following methods:
  5652.  
  5653.               TIEHASH classname, LIST
  5654.               DESTROY this
  5655.               FETCH this, key
  5656.               STORE this, key, value
  5657.               DELETE this, key
  5658.               EXISTS this, key
  5659.               FIRSTKEY this
  5660.               NEXTKEY this, lastkey
  5661.  
  5662.           A class implementing an ordinary array should    have
  5663.           the following    methods:
  5664.  
  5665.               TIEARRAY classname, LIST
  5666.               DESTROY this
  5667.               FETCH this, key
  5668.               STORE this, key, value
  5669.               [others TBD]
  5670.  
  5671.  
  5672.  
  5673.      Page 86                        (printed 10/23/98)
  5674.  
  5675.  
  5676.  
  5677.  
  5678.  
  5679.  
  5680.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5681.  
  5682.  
  5683.  
  5684.           A class implementing a scalar    should have the
  5685.           following methods:
  5686.  
  5687.               TIESCALAR    classname, LIST
  5688.               DESTROY this
  5689.               FETCH this,
  5690.               STORE this, value
  5691.  
  5692.           Unlike dbmopen(), the    tie() function will not    use or
  5693.           require a module for you--you    need to    do that
  5694.           explicitly yourself.    See the    _D_B__F_i_l_e    manpage    or the
  5695.           _C_o_n_f_i_g module    for interesting    tie() implementations.
  5696.  
  5697.           For further details see the _p_e_r_l_t_i_e manpage, the
  5698.           section on _t_i_e_d _V_A_R_I_A_B_L_E.
  5699.  
  5700.       tied VARIABLE
  5701.           Returns a reference to the object underlying
  5702.           VARIABLE (the    same value that    was originally
  5703.           returned by the tie()    call that bound    the variable
  5704.           to a package.)  Returns the undefined    value if
  5705.           VARIABLE isn't tied to a package.
  5706.  
  5707.       time      Returns the number of    non-leap seconds since
  5708.           whatever time    the system considers to    be the epoch
  5709.           (that's 00:00:00, January 1, 1904 for    MacOS, and
  5710.           00:00:00 UTC,    January    1, 1970    for most other
  5711.           systems).  Suitable for feeding to gmtime() and
  5712.           localtime().
  5713.  
  5714.       times      Returns a four-element list giving the user and
  5715.           system times,    in seconds, for    this process and the
  5716.           children of this process.
  5717.  
  5718.               ($user,$system,$cuser,$csystem) =    times;
  5719.  
  5720.  
  5721.       tr///      The transliteration operator.     Same as y///. See the
  5722.           _p_e_r_l_o_p manpage.
  5723.  
  5724.       truncate FILEHANDLE,LENGTH
  5725.  
  5726.       truncate EXPR,LENGTH
  5727.           Truncates the    file opened on FILEHANDLE, or named by
  5728.           EXPR,    to the specified length.  Produces a fatal
  5729.           error    if truncate isn't implemented on your system.
  5730.           Returns TRUE if successful, the undefined value
  5731.           otherwise.
  5732.  
  5733.       uc EXPR
  5734.  
  5735.  
  5736.  
  5737.  
  5738.  
  5739.      Page 87                        (printed 10/23/98)
  5740.  
  5741.  
  5742.  
  5743.  
  5744.  
  5745.  
  5746.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5747.  
  5748.  
  5749.  
  5750.       uc      Returns an uppercased    version    of EXPR.  This is the
  5751.           internal function implementing the \U    escape in
  5752.           double-quoted    strings.  Respects current LC_CTYPE
  5753.           locale if use    locale in force.  See the _p_e_r_l_l_o_c_a_l_e
  5754.           manpage.
  5755.  
  5756.           If EXPR is omitted, uses $_.
  5757.  
  5758.       ucfirst EXPR
  5759.  
  5760.       ucfirst Returns the value of EXPR with the first character
  5761.           uppercased.  This is the internal function
  5762.           implementing the \u escape in    double-quoted strings.
  5763.           Respects current LC_CTYPE locale if use locale in
  5764.           force.  See the _p_e_r_l_l_o_c_a_l_e manpage.
  5765.  
  5766.           If EXPR is omitted, uses $_.
  5767.  
  5768.       umask    EXPR
  5769.  
  5770.       umask      Sets the umask for the process to EXPR and returns
  5771.           the previous value.  If EXPR is omitted, merely
  5772.           returns the current umask.
  5773.  
  5774.           If _u_m_a_s_k(2) is not implemented on your system    and
  5775.           you are trying to restrict access for    _y_o_u_r_s_e_l_f
  5776.           (i.e., (EXPR & 0700) > 0), produces a    fatal error at
  5777.           run time.  If    _u_m_a_s_k(2) is not    implemented and    you
  5778.           are not trying to restrict access for    yourself,
  5779.           returns undef.
  5780.  
  5781.           Remember that    a umask    is a number, usually given in
  5782.           octal; it is _n_o_t a string of octal digits.  See also
  5783.           the oct entry    elsewhere in this documentif all you
  5784.           have is a string.
  5785.  
  5786.       undef    EXPR
  5787.  
  5788.       undef      Undefines the    value of EXPR, which must be an
  5789.           lvalue.  Use only on a scalar    value, an array    (using
  5790.           "@"),    a hash (using "%"), a subroutine (using    "&"),
  5791.           or a typeglob    (using "<*>").    (Saying    undef
  5792.           $hash{$key} will probably not    do what    you expect on
  5793.           most predefined variables or DBM list    values,    so
  5794.           don't    do that; see the _d_e_l_e_t_e    manpage.)  Always
  5795.           returns the undefined    value.    You can    omit the EXPR,
  5796.           in which case    nothing    is undefined, but you still
  5797.           get an undefined value that you could, for instance,
  5798.           return from a    subroutine, assign to a    variable or
  5799.           pass as a parameter.    Examples:
  5800.  
  5801.  
  5802.  
  5803.  
  5804.  
  5805.      Page 88                        (printed 10/23/98)
  5806.  
  5807.  
  5808.  
  5809.  
  5810.  
  5811.  
  5812.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5813.  
  5814.  
  5815.  
  5816.               undef $foo;
  5817.               undef $bar{'blurfl'};     # Compare to: delete $bar{'blurfl'};
  5818.               undef @ary;
  5819.               undef %hash;
  5820.               undef &mysub;
  5821.               undef *xyz;    # destroys $xyz, @xyz, %xyz, &xyz, etc.
  5822.               return (wantarray    ? (undef, $errmsg) : undef) if $they_blew_it;
  5823.               select undef, undef, undef, 0.25;
  5824.               ($a, $b, undef, $c) = &foo;    # Ignore third value returned
  5825.  
  5826.           Note that this is a unary operator, not a list
  5827.           operator.
  5828.  
  5829.       unlink LIST
  5830.  
  5831.       unlink  Deletes a list of files.  Returns the    number of
  5832.           files    successfully deleted.
  5833.  
  5834.               $cnt = unlink 'a', 'b', 'c';
  5835.               unlink @goners;
  5836.               unlink <*.bak>;
  5837.  
  5838.           Note:    unlink() will not delete directories unless
  5839.           you are superuser and    the ----UUUU flag is supplied    to
  5840.           Perl.     Even if these conditions are met, be warned
  5841.           that unlinking a directory can inflict damage    on
  5842.           your filesystem.  Use    rmdir()    instead.
  5843.  
  5844.           If LIST is omitted, uses $_.
  5845.  
  5846.       unpack TEMPLATE,EXPR
  5847.           Unpack() does    the reverse of pack(): it takes    a
  5848.           string representing a    structure and expands it out
  5849.           into a list value, returning the array value.     (In
  5850.           scalar context, it returns merely the    first value
  5851.           produced.)  The TEMPLATE has the same    format as in
  5852.           the pack() function.    Here's a subroutine that does
  5853.           substring:
  5854.  
  5855.               sub substr {
  5856.               my($what,$where,$howmuch) = @_;
  5857.               unpack("x$where a$howmuch", $what);
  5858.               }
  5859.  
  5860.           and then there's
  5861.  
  5862.               sub ordinal { unpack("c",$_[0]); } # same    as ord()
  5863.  
  5864.           In addition, you may prefix a    field with a %<number>
  5865.           to indicate that you want a <number>-bit checksum of
  5866.           the items instead of the items themselves.  Default
  5867.           is a 16-bit checksum.     For example, the following
  5868.  
  5869.  
  5870.  
  5871.      Page 89                        (printed 10/23/98)
  5872.  
  5873.  
  5874.  
  5875.  
  5876.  
  5877.  
  5878.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5879.  
  5880.  
  5881.  
  5882.           computes the same number as the System V sum
  5883.           program:
  5884.  
  5885.               while (<>) {
  5886.               $checksum += unpack("%16C*", $_);
  5887.               }
  5888.               $checksum    %= 65536;
  5889.  
  5890.           The following    efficiently counts the number of set
  5891.           bits in a bit    vector:
  5892.  
  5893.               $setbits = unpack("%32b*", $selectmask);
  5894.  
  5895.  
  5896.       untie    VARIABLE
  5897.           Breaks the binding between a variable    and a package.
  5898.           (See tie().)
  5899.  
  5900.       unshift ARRAY,LIST
  5901.           Does the opposite of a shift().  Or the opposite of
  5902.           a push(), depending on how you look at it.  Prepends
  5903.           list to the front of the array, and returns the new
  5904.           number of elements in    the array.
  5905.  
  5906.               unshift(ARGV, '-e') unless $ARGV[0] =~ /^-/;
  5907.  
  5908.           Note the LIST    is prepended whole, not    one element at
  5909.           a time, so the prepended elements stay in the    same
  5910.           order.  Use reverse()    to do the reverse.
  5911.  
  5912.       use Module LIST
  5913.  
  5914.       use Module
  5915.  
  5916.       use Module VERSION LIST
  5917.  
  5918.       use VERSION
  5919.           Imports some semantics into the current package from
  5920.           the named module, generally by aliasing certain
  5921.           subroutine or    variable names into your package.  It
  5922.           is exactly equivalent    to
  5923.  
  5924.               BEGIN { require Module; import Module LIST; }
  5925.  
  5926.           except that Module _m_u_s_t be a bareword.
  5927.  
  5928.           If the first argument    to use is a number, it is
  5929.           treated as a version number instead of a module
  5930.           name.     If the    version    of the Perl interpreter    is
  5931.           less than VERSION, then an error message is printed
  5932.           and Perl exits immediately.  This is often useful if
  5933.           you need to check the    current    Perl version before
  5934.  
  5935.  
  5936.  
  5937.      Page 90                        (printed 10/23/98)
  5938.  
  5939.  
  5940.  
  5941.  
  5942.  
  5943.  
  5944.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5945.  
  5946.  
  5947.  
  5948.           useing library modules that have changed in
  5949.           incompatible ways from older versions    of Perl.  (We
  5950.           try not to do    this more than we have to.)
  5951.  
  5952.           The BEGIN forces the require and import() to happen
  5953.           at compile time.  The    require    makes sure the module
  5954.           is loaded into memory    if it hasn't been yet.    The
  5955.           import() is not a builtin--it's just an ordinary
  5956.           static method    call into the "Module" package to tell
  5957.           the module to    import the list    of features back into
  5958.           the current package.    The module can implement its
  5959.           import() method any way it likes, though most
  5960.           modules just choose to derive    their import() method
  5961.           via inheritance from the Exporter class that is
  5962.           defined in the Exporter module.  See the _E_x_p_o_r_t_e_r
  5963.           manpage.  If no import() method can be found then
  5964.           the error is currently silently ignored.  This may
  5965.           change to a fatal error in a future version.
  5966.  
  5967.           If you don't want your namespace altered, explicitly
  5968.           supply an empty list:
  5969.  
  5970.               use Module ();
  5971.  
  5972.           That is exactly equivalent to
  5973.  
  5974.               BEGIN { require Module }
  5975.  
  5976.           If the VERSION argument is present between Module
  5977.           and LIST, then the use will call the VERSION method
  5978.           in class Module with the given version as an
  5979.           argument.  The default VERSION method, inherited
  5980.           from the Universal class, croaks if the given
  5981.           version is larger than the value of the variable
  5982.           $Module::VERSION.  (Note that    there is not a comma
  5983.           after    VERSION!)
  5984.  
  5985.           Because this is a wide-open interface, pragmas
  5986.           (compiler directives)    are also implemented this way.
  5987.           Currently implemented    pragmas    are:
  5988.  
  5989.               use integer;
  5990.               use diagnostics;
  5991.               use sigtrap qw(SEGV BUS);
  5992.               use strict  qw(subs vars refs);
  5993.               use subs      qw(afunc blurfl);
  5994.  
  5995.           Some of these    these pseudo-modules import semantics
  5996.           into the current block scope (like strict or
  5997.           integer, unlike ordinary modules, which import
  5998.           symbols into the current package (which are
  5999.           effective through the    end of the file).
  6000.  
  6001.  
  6002.  
  6003.      Page 91                        (printed 10/23/98)
  6004.  
  6005.  
  6006.  
  6007.  
  6008.  
  6009.  
  6010.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  6011.  
  6012.  
  6013.  
  6014.           There's a corresponding "no" command that unimports
  6015.           meanings imported by use, i.e., it calls unimport
  6016.           Module LIST instead of import().
  6017.  
  6018.               no integer;
  6019.               no strict    'refs';
  6020.  
  6021.           If no    unimport() method can be found the call    fails
  6022.           with a fatal error.
  6023.  
  6024.           See the _p_e_r_l_m_o_d manpage for a    list of    standard
  6025.           modules and pragmas.
  6026.  
  6027.       utime    LIST
  6028.           Changes the access and modification times on each
  6029.           file of a list of files.  The    first two elements of
  6030.           the list must    be the NUMERICAL access    and
  6031.           modification times, in that order.  Returns the
  6032.           number of files successfully changed.     The inode
  6033.           modification time of each file is set    to the current
  6034.           time.     This code has the same    effect as the "touch"
  6035.           command if the files already exist:
  6036.  
  6037.               #!/usr/bin/perl
  6038.               $now = time;
  6039.               utime $now, $now,    @ARGV;
  6040.  
  6041.  
  6042.       values HASH
  6043.           Returns a list consisting of all the values of the
  6044.           named    hash.  (In a scalar context, returns the
  6045.           number of values.)  The values are returned in an
  6046.           apparently random order, but it is the same order as
  6047.           either the keys() or each() function would produce
  6048.           on the same hash.  As    a side effect, it resets
  6049.           HASH's iterator.  See    also keys(), each(), and
  6050.           sort().
  6051.  
  6052.       vec EXPR,OFFSET,BITS
  6053.           Treats the string in EXPR as a vector    of unsigned
  6054.           integers, and    returns    the value of the bit field
  6055.           specified by OFFSET.    BITS specifies the number of
  6056.           bits that are    reserved for each entry    in the bit
  6057.           vector.  This    must be    a power    of two from 1 to 32.
  6058.           vec()    may also be assigned to, in which case
  6059.           parentheses are needed to give the expression    the
  6060.           correct precedence as    in
  6061.  
  6062.               vec($image, $max_x * $x +    $y, 8) = 3;
  6063.  
  6064.           Vectors created with vec() can also be manipulated
  6065.           with the logical operators |,    &, and ^, which    will
  6066.  
  6067.  
  6068.  
  6069.      Page 92                        (printed 10/23/98)
  6070.  
  6071.  
  6072.  
  6073.  
  6074.  
  6075.  
  6076.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  6077.  
  6078.  
  6079.  
  6080.           assume a bit vector operation    is desired when    both
  6081.           operands are strings.
  6082.  
  6083.           The following    code will build    up an ASCII string
  6084.           saying 'PerlPerlPerl'.  The comments show the    string
  6085.           after    each step. Note    that this code works in    the
  6086.           same way on big-endian or little-endian machines.
  6087.  
  6088.               my $foo =    '';
  6089.               vec($foo,     0, 32)    = 0x5065726C;      # 'Perl'
  6090.               vec($foo,     2, 16)    = 0x5065;      # 'PerlPe'
  6091.               vec($foo,     3, 16)    = 0x726C;      # 'PerlPerl'
  6092.               vec($foo,     8,  8)    = 0x50;          # 'PerlPerlP'
  6093.               vec($foo,     9,  8)    = 0x65;          # 'PerlPerlPe'
  6094.               vec($foo,    20,  4)    = 2;          # 'PerlPerlPe'   . "\x02"
  6095.               vec($foo,    21,  4)    = 7;          # 'PerlPerlPer'
  6096.                               # 'r'    is "\x72"
  6097.               vec($foo,    45,  2)    = 3;          # 'PerlPerlPer'  . "\x0c"
  6098.               vec($foo,    93,  1)    = 1;          # 'PerlPerlPer'  . "\x2c"
  6099.               vec($foo,    94,  1)    = 1;          # 'PerlPerlPerl'
  6100.                               # 'l'    is "\x6c"
  6101.  
  6102.           To transform a bit vector into a string or array of
  6103.           0's and 1's, use these:
  6104.  
  6105.               $bits = unpack("b*", $vector);
  6106.               @bits = split(//,    unpack("b*", $vector));
  6107.  
  6108.           If you know the exact    length in bits,    it can be used
  6109.           in place of the *.
  6110.  
  6111.       wait      Waits    for a child process to terminate and returns
  6112.           the pid of the deceased process, or -1 if there are
  6113.           no child processes.  The status is returned in $?.
  6114.  
  6115.       waitpid PID,FLAGS
  6116.           Waits    for a particular child process to terminate
  6117.           and returns the pid of the deceased process, or -1
  6118.           if there is no such child process.  The status is
  6119.           returned in $?.  If you say
  6120.  
  6121.               use POSIX    ":sys_wait_h";
  6122.               #...
  6123.               waitpid(-1,&WNOHANG);
  6124.  
  6125.           then you can do a non-blocking wait for any process.
  6126.           Non-blocking wait is available on machines
  6127.           supporting either the    _w_a_i_t_p_i_d(2) or _w_a_i_t_4(2) system
  6128.           calls.  However, waiting for a particular pid    with
  6129.           FLAGS    of 0 is    implemented everywhere.     (Perl
  6130.           emulates the system call by remembering the status
  6131.           values of processes that have    exited but have    not
  6132.  
  6133.  
  6134.  
  6135.      Page 93                        (printed 10/23/98)
  6136.  
  6137.  
  6138.  
  6139.  
  6140.  
  6141.  
  6142.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  6143.  
  6144.  
  6145.  
  6146.           been harvested by the    Perl script yet.)
  6147.  
  6148.           See the _p_e_r_l_i_p_c manpage for other examples.
  6149.  
  6150.       wantarray
  6151.           Returns TRUE if the context of the currently
  6152.           executing subroutine is looking for a    list value.
  6153.           Returns FALSE    if the context is looking for a
  6154.           scalar.  Returns the undefined value if the context
  6155.           is looking for no value (void    context).
  6156.  
  6157.               return unless defined wantarray;      # don't bother doing more
  6158.               my @a = complex_calculation();
  6159.               return wantarray ? @a : "@a";
  6160.  
  6161.  
  6162.       warn LIST
  6163.           Produces a message on    STDERR just like die(),    but
  6164.           doesn't exit or throw    an exception.
  6165.  
  6166.           If LIST is empty and $@ already contains a value
  6167.           (typically from a previous eval) that    value is used
  6168.           after    appending "\t...caught"    to $@. This is useful
  6169.           for staying almost, but not entirely similar to
  6170.           die().
  6171.  
  6172.           If $@    is empty then the string "Warning: Something's
  6173.           wrong" is used.
  6174.  
  6175.           No message is    printed    if there is a $SIG{__WARN__}
  6176.           handler installed.  It is the    handler's
  6177.           responsibility to deal with the message as it    sees
  6178.           fit (like, for instance, converting it into a
  6179.           die()).  Most    handlers must therefore    make
  6180.           arrangements to actually display the warnings    that
  6181.           they are not prepared    to deal    with, by calling
  6182.           warn() again in the handler.    Note that this is
  6183.           quite    safe and will not produce an endless loop,
  6184.           since    __WARN__ hooks are not called from inside one.
  6185.  
  6186.           You will find    this behavior is slightly different
  6187.           from that of $SIG{__DIE__} handlers (which don't
  6188.           suppress the error text, but can instead call    die()
  6189.           again    to change it).
  6190.  
  6191.           Using    a __WARN__ handler provides a powerful way to
  6192.           silence all warnings (even the so-called mandatory
  6193.           ones).  An example:
  6194.  
  6195.  
  6196.  
  6197.  
  6198.  
  6199.  
  6200.  
  6201.      Page 94                        (printed 10/23/98)
  6202.  
  6203.  
  6204.  
  6205.  
  6206.  
  6207.  
  6208.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  6209.  
  6210.  
  6211.  
  6212.               #    wipe out *all* compile-time warnings
  6213.               BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } }
  6214.               my $foo =    10;
  6215.               my $foo =    20;         # no warning about    duplicate my $foo,
  6216.                          # but hey,    you asked for it!
  6217.               #    no compile-time    or run-time warnings before here
  6218.               $DOWARN =    1;
  6219.  
  6220.               #    run-time warnings enabled after    here
  6221.               warn "\$foo is alive and $foo!";       # does show up
  6222.  
  6223.           See the _p_e_r_l_v_a_r manpage for details on setting %SIG
  6224.           entries, and for more    examples.
  6225.  
  6226.       write    FILEHANDLE
  6227.  
  6228.       write    EXPR
  6229.  
  6230.       write      Writes a formatted record (possibly multi-line) to
  6231.           the specified    FILEHANDLE, using the format
  6232.           associated with that file.  By default the format
  6233.           for a    file is    the one    having the same    name as    the
  6234.           filehandle, but the format for the current output
  6235.           channel (see the select() function) may be set
  6236.           explicitly by    assigning the name of the format to
  6237.           the $~ variable.
  6238.  
  6239.           Top of form processing is handled automatically:  if
  6240.           there    is insufficient    room on    the current page for
  6241.           the formatted    record,    the page is advanced by
  6242.           writing a form feed, a special top-of-page format is
  6243.           used to format the new page header, and then the
  6244.           record is written.  By default the top-of-page
  6245.           format is the    name of    the filehandle with "_TOP"
  6246.           appended, but    it may be dynamically set to the
  6247.           format of your choice    by assigning the name to the
  6248.           $^ variable while the    filehandle is selected.     The
  6249.           number of lines remaining on the current page    is in
  6250.           variable $-, which can be set    to 0 to    force a    new
  6251.           page.
  6252.  
  6253.           If FILEHANDLE    is unspecified,    output goes to the
  6254.           current default output channel, which    starts out as
  6255.           STDOUT but may be changed by the select() operator.
  6256.           If the FILEHANDLE is an EXPR,    then the expression is
  6257.           evaluated and    the resulting string is    used to    look
  6258.           up the name of the FILEHANDLE    at run time.  For more
  6259.           on formats, see the _p_e_r_l_f_o_r_m manpage.
  6260.  
  6261.           Note that write is _N_O_T the opposite of read().
  6262.           Unfortunately.
  6263.  
  6264.  
  6265.  
  6266.  
  6267.      Page 95                        (printed 10/23/98)
  6268.  
  6269.  
  6270.  
  6271.  
  6272.  
  6273.  
  6274.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  6275.  
  6276.  
  6277.  
  6278.       y///      The transliteration operator.     Same as tr///.     See
  6279.           the _p_e_r_l_o_p manpage.
  6280.  
  6281.  
  6282.  
  6283.  
  6284.  
  6285.  
  6286.  
  6287.  
  6288.  
  6289.  
  6290.  
  6291.  
  6292.  
  6293.  
  6294.  
  6295.  
  6296.  
  6297.  
  6298.  
  6299.  
  6300.  
  6301.  
  6302.  
  6303.  
  6304.  
  6305.  
  6306.  
  6307.  
  6308.  
  6309.  
  6310.  
  6311.  
  6312.  
  6313.  
  6314.  
  6315.  
  6316.  
  6317.  
  6318.  
  6319.  
  6320.  
  6321.  
  6322.  
  6323.  
  6324.  
  6325.  
  6326.  
  6327.  
  6328.  
  6329.  
  6330.  
  6331.  
  6332.  
  6333.      Page 96                        (printed 10/23/98)
  6334.  
  6335.  
  6336.  
  6337.  
  6338.  
  6339.  
  6340.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))      4444////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))       PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  6341.  
  6342.  
  6343.  
  6344.  
  6345.  
  6346.  
  6347.  
  6348.  
  6349.  
  6350.  
  6351.  
  6352.  
  6353.  
  6354.  
  6355.  
  6356.  
  6357.  
  6358.  
  6359.  
  6360.  
  6361.  
  6362.  
  6363.  
  6364.  
  6365.  
  6366.  
  6367.  
  6368.  
  6369.  
  6370.  
  6371.  
  6372.  
  6373.  
  6374.  
  6375.  
  6376.  
  6377.  
  6378.  
  6379.  
  6380.  
  6381.  
  6382.  
  6383.  
  6384.  
  6385.  
  6386.  
  6387.  
  6388.  
  6389.  
  6390.  
  6391.  
  6392.  
  6393.  
  6394.  
  6395.  
  6396.      Page 97                        (printed 10/23/98)
  6397.  
  6398.  
  6399.  
  6400.  
  6401.  
  6402.  
  6403.